adi's example could be more clearly presented as:
<?php
$result = mysql_query("SELECT name FROM whatever");
$num_rows = mysql_num_rows($result);
$a = array();
while ($row = mysql_fetch_array($result))
{
$a[] = $row['name'];
}
echo '<table> ';
for ($i = 0; $i < $num_rows; $i++)
{
echo '<tr><td>' . $a[$i] . '</td>';
$i++;
echo '<td>' . $a[$i] . '</td>';
$i++;
echo '<td>' . $a[$i] . '</td></tr>';
}
echo '</table>';
?>
Conversely, you could use an algorithm such as:
Submit query
Start table
Set $count = 0
Loop through query result set
If $count % 3 == 0
Start new row
Endif
Write data cell content
If $count % 3 == 2
End current row
Endif
Increment $count
Endloop
If $count % 3 != 0
End last row
Endif
End table
e.g.
<?php
$result = mysql_query("SELECT name FROM whatever");
echo '<table> ';
$count = 0;
while ($row = mysql_fetch_array($result))
{
if ($count % 3 == 0)
{
echo '<tr>';
}
echo '<td>' . $row['name'] . '</td>';
if ($count % 3 == 2)
{
echo '</tr>'
}
$count++;
}
if ($count % 3 != 0)
{
echo '</tr>';
}
?>