Here's a working example:
<table cellpadding="5" cellspacing="0" border="0">
<?
$maxcolumns = 4; // how many columns do you want? Enter it here
$nRecordCounter = 0; // need to reset the record counter
for($a = 0; $a < 43; $a++) // using for() for example - here would be your query's while()
{
if($nRecordCounter % $maxcolumns == 0) // check if start of row
echo '<tr>'; // yup, it is!
echo '<td>' . $a . '</td>'; // dump one record - who cares where it goes!
$nRecordCounter++; // in this example I could have just used $a, but if you're in a while(), you'll need this line
if($nRecordCounter % $maxcolumns == 0) // check if end of row
echo '</tr>'; // yup, it is!
} // end for($a = 0; $a < 40; $a++)
?>
</table>
Give that a whirl. Just swap out the for() with your query's while loop and then tweak the echo statement to dump out the necessary goodies to present one record.
All I'm doing is keeping track of how many records have been processed and taking the modulus (or the remainder - the "%") and if the remainder is 0 from the operation, then we must be working on a new row. Once the record has been displayed (the echo statement) then we increment the record counter and check again if we're at the end of the row. If we are, dump the necessary HTML. Rinse and repeat...
Silly tabs don't want to line up the comments in the code - excuse the formatting