When dealing purely with HTML, especially tables, or other things in "grids" the modulous operator is really useful for splitting up the data with a seperator.
This snippet reads any gif files from the directory the script is in, prints them out and puts in a break every 5th image.
<?php
$d = dir('./');
$i = 0;
while(false !== ($e = $d->read())){
if(strpos($e,'.gif')){
++$i;
echo '<img src="'.$e.'"/>'.chr(10);
if(!($i%5))
echo '<br/>';
}
}
?>
For tables just put </tr><tr> in place of the break.