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>
";
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:So that the
</tr>is in sync with the next loops<tr>.