This is a function I use normally in a class, so if any of the $res bits are wrong they're normally $this->res, so just change that to $res.
You pass it the result from a mysql_query, and a format string for the table and if the show header thing is true it'll also print the column names
function show_table($res, $fmt='border="1" style="border-collapse: collapse"', $showHeader=TRUE)
{
if(!$res || ($nf = mysql_num_fields($res))==0 ) return;
echo "<table $fmt>";
if($showHeader)
{
echo '<tr>';
//the fields start at zero, unlike odbc, apparently
for ($c=0; $c<$nf; $c++) echo '<th>'.mysql_field_name($res, $c).'</th>';
echo "</tr>\n";
}
while ( $row = mysql_fetch_row($res) )
{
echo '<tr>';
for ($c=0; $c<$nf; $c++)
{
if ( ($cell=$row[$c])=='' ) $cell=" ";
echo "<td>$cell</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
}