$counter=3; $rows = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "table WHERE active='1'"); while ($row = $db->fetch_array($rows)) { if($counter % 3 == 0){ echo "<tr>"; } ?> <td> <?php echo $row['name']; ?> </td> <?php if($counter % 3 == 0){ echo "</tr>"; $counter=1; } $counter++; }