Use mysql_fetch_array and foreach() to step through the array you have created. This example will create a table and a single row and fill it with cells. When it hits 6 cells, it will create a new row. I hope this is what you are looking for!
(I'm bad at HTML so ignore my poor syntax)
<TABLE>
<?php
// Generic MySQL query junk
$query = "SELECT id from cats";
$run = mysql_query($query);
$results = mysql_fetch_array($run);
// Establish our pointer
$z = 0;
// Go through each of our result lines
foreach ($results as $value) {
// z is 0, create a new row
if ($z = 0) { print "<TR><TD>$value</TD>\n"; }
// z is greater than 0 and less than 5, just the TD
elseif ($z > 0 && $z < 5) { print "<TD>$value</TD>\n"; }
// z is 5, the td, end the row and reset z
elseif ($z = 5) { print "<TD>$value</TD></TR>\n"; $z = 0;}
}
?>
</TABLE>