I want three items per row, I know I can count using $i++; but how do I work out that i've had 3 items in a row and i now need to echo "<tr>"
<table> <?php $i = 1; while ($row = mysql_fetch_array($result)) { if($i == 1) { ?> <tr> <?php } ?> <td><?php echo $row['Something']; ?></td> <?php if($i == 3) { ?> </tr> <?php $i = 0; } $i++; } ?> </table>
the modulus operator is often used for that
if (($i % 3) == 1){ //every third row }
if (($i % 2) == 1){ //every second row }