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