php 迴圈異常

來源:互聯網
上載者:User
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 ""; //輸出 即為 換行
} ?>

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.