You need to know how many columns in your table before you attempt to make it. Then print the first opening lines of your table out before you start to loop through the results.
PHP Code:
echo "<table><tr><td> col 1 </td><td> col 2 </td><td> col 3 </td><td> col 4 </td></tr>";
while ($row = mysql_fetch_array ($dbresults) ) {
echo "<tr><td> data </td><td> data </td><td> data </td><td> data </td></tr>";
} // close while
echo "</table>";