PHP:结束并开始新的< tr> 6行之后 [英] PHP: End and start a new <tr> after 6 rows

查看:64
本文介绍了PHP:结束并开始新的< tr> 6行之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一张表,然后每6行应有一个tr,然后这些行都在td内.

I want to make a table, and then for each 6 rows should have a tr, and then the rows are inside td.

例如:

<tr>
<td><?php echo $show[id]; ?></td> // 1
<td><?php echo $show[id]; ?></td> // 2
<td><?php echo $show[id]; ?></td> // 3
<td><?php echo $show[id]; ?></td> // 4
<td><?php echo $show[id]; ?></td> // 5
<td><?php echo $show[id]; ?></td> // 6
</tr> <tr> // start new tr after 6 rows
...repeat the tds

我该怎么做? 我已经尝试过了

How can i do something like this? I have tried myself doing

<tr> 
<?php
while ($show == mysql_fetch_array($query)){ ?>
<td><?php echo $show[id]; ?></td>
<?php } ?>
</tr>

但是您可以看到,这只是将所有内容插入到一个tr中.

But as you can see this just inserts everything in one tr..

谢谢

推荐答案

<tr> 
<?php
$c = 0; // Our counter
$n = 6; // Each Nth iteration would be a new table row
while ($show = mysql_fetch_array($query))
{
  if($c % $n == 0 && $c != 0) // If $c is divisible by $n...
  {
    // New table row
    echo '</tr><tr>';
  }
  $c++;
  ?>
  <td><?php echo $show[id]; ?></td>
  <?php
} ?>
</tr>

相关链接:

这篇关于PHP:结束并开始新的&lt; tr&gt; 6行之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆