$i = 1;$perline = 2;echo "<table><tr>";// while (...{ if(($i % $perline) == 0) { echo "</tr><tr>"; } // Do your stuff $i++;} echo "</tr></table>";