Home  >  Article  >  Backend Development  >  php循环输出表格错位的问题

php循环输出表格错位的问题

WBOY
WBOYOriginal
2016-06-23 14:15:421155browse

<div class="wpzj">  <h1 class="neiyi">外聘专家</h1>    <ul class="bkm">    	<li class="hong">姓    名</li>        <li>职称</li>        <li>价格</li>        <li class="hong">姓    名</li>        <li>职称</li>        <li>价格</li>        <li class="hong">姓    名</li>        <li>职称</li>        <li class="bkym">价格</li>    </ul>    <ul class="bkm"><li class="hong">刘    红</li>        <li></li>        <li></li>        <li class="hong">祝    蓉</li>        <li></li>        <li></li>        <li class="hong">吴金荣</li>        <li></li>        <li class="bkym"></li>    </ul>      <ul class="bkm">    	<li class="hong">刘燕池</li>        <li></li>        <li></li>        <li class="hong"></li>        <li></li>        <li></li>        <li class="hong"></li>        <li></li>        <li class="bkym"></li>    </ul></div>

我想输出这个表格,可是到了第二行的时候就只显示一个然后换行,我用table的时候没问题。
<?php 	  		if ( isset($arrayServiceType) && is_array($arrayServiceType) ) {	  			$strWaiDoctor = "";	  			for ($i=0; $i< count($arrayServiceType); $i++) {	  				if($i%4==0){	  					$strWaiDoctor.="<ul class=\"bkm\">";	  				}	  					  				if ( $arrayServiceType[$i]['type'] == '1' ) {	  					if(($i+1) % 4 == 0) {	  						$strWaiDoctor.="<li class=\"hong\"><a href=\"showorderinginfo.php?cardnumber=".$_REQUEST['cardnumber']."&organid=".$_REQUEST['organid']."&orderingid=".$_REQUEST['orderingid']."&serviceid=".$arrayServiceType[$i]['服务编号']."&doctorid=".$arrayServiceType[$i]['doctorid']."&showdoctorinfo=display\">".$arrayServiceType[$i]['doctorname']."</a> </li><li></li><li style=\"border-right:none;\">".$arrayServiceType[$i]['金额']."元</li>";	  					}else{	  						$strWaiDoctor.="<li class=\"hong\"><a href=\"showorderinginfo.php?cardnumber=".$_REQUEST['cardnumber']."&organid=".$_REQUEST['organid']."&orderingid=".$_REQUEST['orderingid']."&serviceid=".$arrayServiceType[$i]['服务编号']."&doctorid=".$arrayServiceType[$i]['doctorid']."&showdoctorinfo=display\">".$arrayServiceType[$i]['doctorname']."</a> </li><li></li><li>".$arrayServiceType[$i]['金额']."元</li>";	  					}	  				}	  					  				if(($i+1) % 4 == 0) {	  				//	if(($i+1) % 3 == 0) {	  					$strWaiDoctor.= "</ul>";	  				}	  			}	  			echo $strWaiDoctor;	  		}	?>


回复讨论(解决方案)

<?php               if ( isset($arrayServiceType) && is_array($arrayServiceType) ) {                  $strWaiDoctor = "";                  for ($i=0; $i< count($arrayServiceType); $i++) {                      if($i%4==0){                          $strWaiDoctor.="<ul class=\"bkm\">";                      }                                            if ( $arrayServiceType[$i]['type'] == '1' ) {                          if(($i+1) % 4 == 0) {                              $strWaiDoctor.="<li class=\"hong\"> <a href=\"showorderinginfo.php?cardnumber=".$_REQUEST['cardnumber']."&organid=".$_REQUEST['organid']."&orderingid=".$_REQUEST['orderingid']."&serviceid=".$arrayServiceType[$i]['服务编号']."&doctorid=".$arrayServiceType[$i]['doctorid']."&showdoctorinfo=display\">".$arrayServiceType[$i]['doctorname']."</a> </li><li> </li><li style=\"border-right:none;\"> ".$arrayServiceType[$i]['金额']."元</li>";                          }else{                              $strWaiDoctor.="<li class=\"hong\"> <a href=\"showorderinginfo.php?cardnumber=".$_REQUEST['cardnumber']."&organid=".$_REQUEST['organid']."&orderingid=".$_REQUEST['orderingid']."&serviceid=".$arrayServiceType[$i]['服务编号']."&doctorid=".$arrayServiceType[$i]['doctorid']."&showdoctorinfo=display\">".$arrayServiceType[$i]['doctorname']."</a> </li> <li> </li><li> ".$arrayServiceType[$i]['金额']."元</li>";                          }                      }                                            if(($i+1) % 4 == 0) {                      //    if(($i+1) % 3 == 0) {                          $strWaiDoctor.= "</ul>";                      }                  }                  echo $strWaiDoctor;              }    ?>


试试

楼上的兄弟还是不行啊

<div class="wpzj">  <h1 class="neiyi">外聘专家</h1>    <ul class="bkm">    	<li class="hong">姓    名</li>        <li>职称</li>        <li>价格</li>        <li class="hong">姓    名</li>        <li>职称</li>        <li>价格</li>        <li class="hong">姓    名</li>        <li>职称</li>        <li class="bkym">价格</li>    </ul>    <ul class="bkm"><li class="hong">刘    红</li>        <li></li>        <li></li>        <li class="hong">祝    蓉</li>        <li></li>        <li></li>        <li class="hong">吴金荣</li>        <li></li>        <li class="bkym"></li>    </ul>      <ul class="bkm">    	<li class="hong">刘燕池</li>        <li></li>        <li></li>        <li class="hong">刘燕池1</li>        <li></li>        <li></li>        <li class="hong">刘燕池1</li>        <li></li>        <li class="bkym"></li>    </ul></div>

没有人知道吗?
拜托啊

不用贴你的PHP代码,看看HTML代码是否完整,如果完整的话,那肯定就是CSS写的不对了,可以去页面设计的版面论坛去问问……

在HTML代码里面显示的是没问题的

就没人知道怎么回事吗

应该是你的程序判断的原因

utf-8的问题,你把文件都改成ANSI就可以了,参考http://blog.csdn.net/aniven/article/details/6925561

Statement:
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
Previous article:二级分类添加文章Next article:UDP校验和的计算方法