PHP: Finish and start a new <tr> after 6 lines
I want to create a table, and then for each 6 rows there should be tr, and then the rows are inside td.
So an example:
<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 tried to do myself
<tr>
<?php
while ($show == mysql_fetch_array($query)){ ?>
<td><?php echo $show[id]; ?></td>
<?php } ?>
</tr>
But, as you can see, this just inserts everything into one tr ..
thank
+3
5 answers
<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>
Related links:
+18