[英]php for loop skips by twos
I have a function in php that builds an html string for a table so at inside I have a for loop 我在php中有一个函数,可以为表建立一个html字符串,所以在里面我有一个for循环
for ($counter = 0; $counter<10; $counter++){
$htmlString .= code for table row here;
}
The for loop only makes 5 rows and i even printed out the value of $counter and it says: 0, 2, 4, 6, 8 for循环仅产生5行,我什至打印出$ counter的值,它表示:0、2、4、6、8
I have never seen this before and I can't think of any way to fix this other than changing the loop from 10 to 20 but I rather know what is causing this so I can fix it for good. 我以前从未见过此问题,除了将循环从10更改为20之外,我没有其他方法可以解决此问题,但我更清楚是什么原因造成的,所以我可以永久修复它。
here is my full code for the function i pass in a row from a sql db: 这是我从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>  ; $counter</td>";
}
$NetworkHtml .= "</tr></table>";
return $NetworkHtml;
}
Try changing: 尝试更改:
"<td style='width:10%; height:80px>  ; $counter</td>"
to: 至:
"<td style='width:10%; height:80px'> $counter</td>"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.