类似于上面的样子,里面的每行数据都是循环出来的,但是加入只有2条数据的话肯定就只输出2行了,剩余的6行压根就会不显示。
怎么才能让剩余的6行进行空输出以保证整个表格的样式的规整?

解决方案 »

  1.   

    你这个是什么循环?  js   php   smarty??
    说下原理吧  其实就是用个变量计数  每次循环判断这个变量有没有达到你要求的数量  没有就continue
      

  2.   

    <?php
                    $db->Query("list","select * from #@__cp where `pid`=$row[id] order by `id` desc");
                    while($res=$db->GetArray("list")){
                ?>
                <tr style="text-align:center;">
                    <td width="10%"><?=$res[title]?></td>
                    <td width="7%"><?=$res[gangzhong]?></td>
                    <td width="16%"><?=$res[biaozhun]?></td>
                    <td width="16%"><?=$res[guige]?></td>
                    <td width="10%"><?=$res[weight]?></td>
                    <td width="10%"><?=$res[amount]?></td>
                    <td width="10%"><?=$res[single_price]?></td>
                    <td width="10%"><?=$res[total_price]?></td>
                    <td width="10%"><?=$row[content]?></td>
                </tr>
                <?
                }
                ?>
      

  3.   

    <?php
    $db->Query("list","select * from #@__cp where `pid`=$row[id] order by `id` desc");
    $h = 8; //你需要的行数
    for($i=0; $i<$h; $i++) {
      if($res=$db->GetArray("list")) {
    ?>
    <tr style="text-align:center;">
      <td width="10%"><?=$res[title]?></td>
      <td width="7%"><?=$res[gangzhong]?></td>
      <td width="16%"><?=$res[biaozhun]?></td>
      <td width="16%"><?=$res[guige]?></td>
      <td width="10%"><?=$res[weight]?></td>
      <td width="10%"><?=$res[amount]?></td>
      <td width="10%"><?=$res[single_price]?></td>
      <td width="10%"><?=$res[total_price]?></td>
      <td width="10%"><?=$row[content]?></td>
    </tr>
    <?
      }else {
        echo "<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>";
      }
    }
    ?>