$result = mysql_query($sql) or die(mysql_error()); $i = 0; echo '<tr>'; while ($row = mysql_fetch_assoc($result)) { if($i % 3 == 0 && $i != 0) { echo '</tr><tr>'; } echo '<td>', $row['submission_id'], '</td>'; $i++; } echo '</tr>';