This code will close any additional lines:
<table> <?php $i = 0; while($row = mysql_fetch_array($result)){ $i++; //if this is first value in row, create new row if ($i % 3 == 1) { echo "<tr>"; } echo "<td>".$row[0]."</td>"; //if this is third value in row, end row if ($i % 3 == 0) { echo "</tr>"; } } //if the counter is not divisible by 3, we have an open row $spacercells = 3 - ($i % 3); if ($spacercells < 3) { for ($j=1; $j<=$spacercells; $j++) { echo "<td></td>"; } echo "</tr>"; } ?> </table>
Nicholas kouvatsos
source share