<? $var = 1; while (........) { if (($var % 3) == 0) echo "<tr>"; echo $link; if (($var % 3) == 0) echo "</tr>"; $var= $var +1; } ?>