I have a table and needs <tr>
to be appended every 3 td
<?php
$sql = mysql_query("SELECT * FROM products");
$count = 1;
while($row = mysql_fetch_array($sql)) {
if($c % 3 == 0) echo "<tr>";
echo "
<td>
$row['name'];
</td>
开发者_Go百科 ";
if($c % 3 == 0) echo "</tr>";
$c++;
}
?>
This comes up as
[] []
[]
[] []
[]
instead of
[] [] []
[] [] []
where []
means the data placement
You need to switch the </tr>
output and the $c++
counting:
$c++;
if($c % 3 == 0) echo "</tr>";
}
So that the </tr>
is in sync with the next loops <tr>
.
精彩评论