<?php
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="description" content="Database List">
   <title>Database List</title>
</head>
<body>

<?php

if ($location1=="database")
{
  $chandle = mysql_pconnect("localhost", $username, $password) 
      or die("Connection Failure to Database");
  session_register("database");
  $database=$QUERY_STRING;  // The database name is passed using QUERY_STRING
  mysql_select_db($database, $chandle) or die ("Database not found.");
  $tablelist=mysql_list_tables($database);
  echo "<H3>Available Tables in the ", $database, " Database:</H3>";
  echo "<UL>";
  $table = 0;
  while ($table < mysql_num_rows($tablelist))
  {
    $tablename=mysql_tablename($tablelist, $table);
    echo "<LI><A href=\"dblist.php?", $tablename, "\">", $tablename, "</A><BR>";
    $table++;
  }
  echo "</UL>";
  mysql_close($chandle);
  $location1="table";
}
elseif ($location1=="table")
{
  $chandle = mysql_pconnect("localhost", $username, $password) 
     or die("Connection Failure to Database");
  mysql_select_db($database, $chandle) or die ("Database not found.");
  $query1="select * from " . $QUERY_STRING;
  $result = mysql_db_query($database, $query1) or die("Failed Query");
  $i=0;
  echo "<table rules=\"all\"><tr>";
  while ($i < mysql_num_fields($result))
  {
    $field_name=mysql_fetch_field($result, $i);
    echo "<th>", $field_name->name, "</th>";
    $i++;
  }
  echo "</tr>";
  while ($thisrow=mysql_fetch_row($result))  //get one row at a time
  {
    echo "<tr>";
    $i=0;
    while ($i < mysql_num_fields($result))  //print all items in the row
    {
      echo $thisrow[$i], "<br>";
      $i++;
    }
    echo "</tr>";
  }
  echo "</table>";
  mysql_free_result($result);
  mysql_close($chandle);
}
?>

</body>
</html>
 
From here