noganno
9/7/2015 - 6:59 AM

From http://stackoverflow.com/questions/9008522/insert-tr-after-every-third-loop

<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>