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","REM OVED","REMOVED" );
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("db_0300931 9", $con);
?>
<?php $selectedTable= $_GET["selectedTa ble"] ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitl ed Document</title>
</head>
<body>
<?php echo $_GET["selectedTa ble"]; ?>
<table border=1>
<tr>
<?php
$headers = mysql_query("de scribe $selectedTable" );
while($row = mysql_fetch_arr ay($headers))
{
?>
<th><?php echo $row[0]; ?></th>
<?php
}
?>
</tr>
<?php
$headers = mysql_query("de scribe $selectedTable" );
$data = mysql_query("se lect * from $selectedTable" );
while($temp = mysql_fetch_arr ay($data))
{
?>
<tr>
<?php
$i=0;
while(mysql_fet ch_array($heade rs))
{
?>
<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
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","REM OVED","REMOVED" );
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("db_0300931 9", $con);
?>
<?php $selectedTable= $_GET["selectedTa ble"] ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitl ed Document</title>
</head>
<body>
<?php echo $_GET["selectedTa ble"]; ?>
<table border=1>
<tr>
<?php
$headers = mysql_query("de scribe $selectedTable" );
while($row = mysql_fetch_arr ay($headers))
{
?>
<th><?php echo $row[0]; ?></th>
<?php
}
?>
</tr>
<?php
$headers = mysql_query("de scribe $selectedTable" );
$data = mysql_query("se lect * from $selectedTable" );
while($temp = mysql_fetch_arr ay($data))
{
?>
<tr>
<?php
$i=0;
while(mysql_fet ch_array($heade rs))
{
?>
<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
Comment