E' molto più facile rispetto al procedimento che stai usando.

Codice PHP:
$query mysql_query("select campo1,campo2 from tabella") or die(mysql_error());

echo 
'<table>';
while (
$row mysql_fetch_assoc($query))
{
echo 
'<tr>';
echo 
"<td>$row[campo1]</td>";
echo 
"<td>$row[campo2]</td>";
echo 
'</tr>';
}
echo 
'</table>'