首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

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

2013-07-23 
php循环输出表格错位的问题div classwpzjh1 classneiyi外聘专家/h1ul classbkmli class

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

<div class="wpzj">
  <h1 class="neiyi">外聘专家</h1>
    <ul class="bkm">
    <li class="hong">姓&nbsp;&nbsp;&nbsp;&nbsp;名</li>
        <li>职称</li>
        <li>价格</li>
        <li class="hong">姓&nbsp;&nbsp;&nbsp;&nbsp;名</li>
        <li>职称</li>
        <li>价格</li>
        <li class="hong">姓&nbsp;&nbsp;&nbsp;&nbsp;名</li>
        <li>职称</li>
        <li class="bkym">价格</li>
    </ul>
    <ul class="bkm">
<li class="hong">刘&nbsp;&nbsp;&nbsp;&nbsp;红</li>
        <li></li>
        <li></li>
        <li class="hong">祝&nbsp;&nbsp;&nbsp;&nbsp;蓉</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>&nbsp;</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>&nbsp;</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">&nbsp;<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>&nbsp;</li><li>&nbsp;</li><li style="border-right:none;">&nbsp;".$arrayServiceType[$i]['金额']."元</li>";
                          }else{
                              $strWaiDoctor.="<li class="hong">&nbsp;<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>&nbsp;</li>&nbsp;<li>&nbsp;</li><li>&nbsp;".$arrayServiceType[$i]['金额']."元</li>";
                          }
                      }
                      


                      if(($i+1) % 4 == 0) {
                      //    if(($i+1) % 3 == 0) {
                          $strWaiDoctor.= "</ul>";
                      }
                  }
                  echo $strWaiDoctor;
              }
    ?>



试试

热点排行