Hi,
You will need to use mysql_list_tables() to get the table names. For details see:
www.php.net
Here is my version of how to output the data, which I think is a little more efficient and a little more straight forward:
PHP Code:
<?php
//Connect to the database:
$connection=mysql_connect("localhost", "", "")
or die("Couldn't connect to server.");
$db=mysql_select_db("db_name", $connection)
or die("Couldn't select database.");
//Select the data from the table and get the number of fields:
$sql="SELECT * FROM $table_name";
$sql_result=mysql_query($sql);
$num_fields=mysql_num_fields($sql_result);
echo '<table>';
echo '<tr>';
//Display the field names as column headings:
for ($i=0; $i< $num_fields; $i++)
{
echo '<th>';
echo mysql_field_name($sql_result, $i);
echo '</th>';
}
echo '</tr>';
//Get the individual records from the table:
while ($row=mysql_fetch_row($sql_result))
{
echo '<tr>';
//Display all the fields in the record:
for ($i=0; $i< $num_fields; $i++)
{
echo '<td>';
if ($row[$i]='';)
{
echo ' ';
}
else
{
echo $row[$i];
}
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
Bookmarks