For some reason, this code is running the foreach loop twice for each cell. It is driving me crazy! You can see an example here: http://lwhitin.is2.byuh.edu/test/tv.php
It is supposed to take the q argument which is the table name and then return the contents of that table. But somethings going wrong.... Please help if you can. Thanks!
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$sql="SELECT * FROM $q";
$result = mysql_query($sql);
echo "<table border='1'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
foreach ($row as $cell)
{echo "<td>$cell</td>";}
echo "</tr>\n";
}
echo "</table>";
mysql_close($con);
?>