|
Posted by McGowan on 01/26/07 17:19
Hi, I'm trying to display data from a mysql database in a HTML table
but for some reason my code isn't working. At the moment I have got it
to read and display the headers and the first row of the table and it
actually creates the remaining rows in the html table but it doesn't
put any data in them. This is my code so far:
<?php
$con = mysql_connect("localhost","REMOVED","REMOVED");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_03009319", $con);
?>
<?php $selectedTable=$_GET["selectedTable"] ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>
<body>
<?php echo $_GET["selectedTable"]; ?>
<table border=1>
<tr>
<?php
$headers = mysql_query("describe $selectedTable");
while($row = mysql_fetch_array($headers))
{
?>
<th><?php echo $row[0]; ?></th>
<?php
}
?>
</tr>
<?php
$headers = mysql_query("describe $selectedTable");
$data = mysql_query("select * from $selectedTable");
while($temp = mysql_fetch_array($data))
{
?>
<tr>
<?php
$i=0;
while(mysql_fetch_array($headers))
{
?>
<td><?php echo $temp[$i]; ?></td>
<?php
$i++;
}
?>
</tr>
<?php
}
?>
</table>
</body>
</html>
It displays various tables depending on which table name is passed to
it through the url so the number of columns cannot be a fixed number.
Any help would be appreciated.
Thanks,
Oliver
Navigation:
[Reply to this message]
|