The easiest way to do this is probably by setting a counter in your loop
echo "<table><tr>";
$i = 1;
$cols = 4; //number of columns;
while (something){
if ($i > $cols){
echo "<tr>"; //create new row
echo "<td>Data cell $i</td>";
$i = 1; //reset counter;
}else{
echo "<td>Data cell $i</td>";
$i++;
}
} //end while loop
echo "</table>";
you dont have to do this using a table either, you could uses spaces and breaks/new lines