繁体   English   中英

php for循环跳过两位

[英]php for loop skips by twos

我在php中有一个函数,可以为表建立一个html字符串,所以在里面我有一个for循环

for ($counter = 0; $counter<10; $counter++){
  $htmlString .= code for table row here;
}

for循环仅产生5行,我什至打印出$ counter的值,它表示:0、2、4、6、8

我以前从未见过此问题,除了将循环从10更改为20之外,我没有其他方法可以解决此问题,但我更清楚是什么原因造成的,所以我可以永久修复它。

这是我从sql db中连续传递的函数的完整代码:

function BuildNetworkString($Query){
        $NetworkHtml = "<table style='width:100%;'><tr>";
        $counter = 0;
        if($Query['FacebookID'] != '')
        {
            $NetworkHtml .= "<td style='width:10%; height:80px; text-align:center;'><a href='http://facebook.com/profile.php?id=" . $Query['FacebookID'] . "' class='black' title='Facebook - " . $Query['FacebookName'] . "'><img width='50px' src='Images/facebook.png'></a></td>";
            $counter+=1;
        }
        for ($counter; $counter<10; $counter++)
        {
            $NetworkHtml .= "<td style='width:10%; height:80px>&nbsp ;&nbsp;$counter</td>";
        }
        $NetworkHtml .= "</tr></table>";
        return $NetworkHtml;
    }

尝试更改:

"<td style='width:10%; height:80px>&nbsp ;&nbsp;$counter</td>"

至:

"<td style='width:10%; height:80px'>&nbsp;&nbsp;$counter</td>"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM