PHP Code:
<?php
$mysql = mysql_connect('localhost','root','') or die ('Could not connect to MySQL: ' . mysql_error());
mysql_select_db('test') or die ('Could not select the database: ' . mysql_error());
$tables = array('table_1', 'table _2', 'etc');
$content = '';
foreach($tables as $table){
$content .= print_table($table);
}
function print_table($tablename)
{
$query = "SELECT * FROM $tablename";
$query_result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($query_result) > 0)
{
$return = '<table class="mysql_table" border="1" cellspacing="0" cellpadding="6">'."\n".
'<caption>Table name: "'.$tablename.'"</caption>'."\n";
$first_time = true;
while($row = mysql_fetch_assoc($query_result))
{
if($first_time)
{
$first_time = false;
$headings = array_keys($row);
$return .= '<tr>';
foreach($headings as $heading)
{
$return .= '<th>'.$heading.'</th>';
}
$return .= '</tr>'."\n";
}
$return .= '<tr>';
foreach($headings as $heading)
{
$return .= '<td>';
$return .= ($row[$heading]) ? $row[$heading] : ' ';
$return .= '</td>';
}
$return .= '</tr>'."\n";
}
$return .= '</table>'."\n";
return $return;
}
else
{
return 'The table "'.$tablename.'" does not have anything in it yet<br>'."\n";
}
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.mysql_table caption{
color: #008;
font-size: 9pt;
font-family: verdana, sans-serif;
margin: 0 0 5px 0;
white-space: nowrap;
}
.mysql_table th{
color: #008;
font-size: 8pt;
font-family: verdana, sans-serif;
white-space: nowrap;
}
.mysql_table td{
color: #008;
font-size: 8pt;
font-family: verdana, sans-serif;
white-space: nowrap;
}
</style>
<title>View tables</title>
</head>
<body>
<?php echo $content ?>
</body>
</html>
Bookmarks