php 迴圈錯誤
include_once 'mysql.php';
$C = "";
$rownum = 5; //每行要顯示的車標數
$picindex = 1; //$picindex 車標序號
$newrow = 0; //是否換行 ,值為 1 時換行(換行即為要輸入 ,為 0 時不換行
$logorst = mysqli_query($cnn,"select * from BandLogo where ShowOrder <> '0' ORDER BY ShowOrder ASC");
?>
while($row = mysqli_fetch_array($logorst)){ if($picindex > $rownum){ $picindex = 1; $newrow = 1; } if($newrow == 1){ echo "
"; //輸出
即為 換行 } ?>
| if($newrow == 1){ echo "
"; $newrow = 0; } $picindex++; } ?>
上面的代碼想要每行顯示5個表徵圖,但是從第二行開始,就會在第一個圖片顯示了之後換行,請幫我看看那裡有錯誤呢,謝謝了
------解決方案--------------------
你的
if($newrow == 1){
echo ""; //輸出 即為 換行
}
if($newrow == 1){
echo "";
$newrow = 0;
}
是在一次迴圈中完成的,自然那行就只有一個儲存格了
------解決方案--------------------
標籤不完整
if($picindex > $rownum){
$picindex = 1;
$newrow = 1;
}
前五次$picindex 肯定小於$rownum ,也就是說剛開始並沒有的開始標籤
------解決方案--------------------
迴圈裡面改為
if($picindex > $rownum){
$picindex = 1;
}
if($picindex == 1){
echo ""; //輸出 即為 換行
} ?>