Home > Backend Development > PHP Tutorial > php 循环异常

php 循环异常

WBOY
Release: 2016-06-13 12:06:00
Original
1204 people have browsed it

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++;                  
}
 ?>
     
        
              
           
           ">
php 循环异常 "/>

        

          ">
         
        
            
      
    





上面的代码想要每行显示5个图标,但是从第二行开始,就会在第一个图片显示了之后换行,请帮我看看那里有错误呢,谢谢了
------解决方案--------------------
你的
      if($newrow == 1){         
         echo " ";                  //输出   即为 换行         
      }
     if($newrow == 1){
         echo "";
         $newrow = 0;
      }    
是在一次循环中完成的,自然那行就只有一个单元格了
------解决方案--------------------
标签不完整
if($picindex > $rownum){
         $picindex = 1;
         $newrow = 1;
      }   

前五次$picindex 肯定小于$rownum ,也就是说刚开始并没有的开始标签
------解决方案--------------------
循环里面改为
      if($picindex > $rownum){<br>         $picindex = 1;<br>      }         <br>      if($picindex == 1){         <br>         echo "<tr>";                  //输出 </tr><tr> 即为 换行         <br>      } ?>    <br>      <td>     <br>        <table><tr><td>              <?php  //定义一个小的表格,只有两个格子,上面一个格子放图片,下面一个格子放名称  ?><div class="clear">
                 
              
              
        
            </div>
</td></tr></table>
</td>
</tr>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template