<?php $result = $DB_site->query("SELECT * FROM tblName"); $cellcounter = 0; while ($row = $DB_site->fetch_array($result) and ++$cellcounter) { if ($cellcounter%3 == 0) { echo "<tr>\n"; } echo "<td>" . $data . "</td>\n"; if ($cellcounter%3 == 0) { echo "</tr>\n"; } } ?>