簡體   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