How would you echo out a MySQL table into a html table. Like phpMyAdmin shows a table, just a basic table structure with the name of the fields and all the records in that table.
Any help would be appreciated
How would you echo out a MySQL table into a html table. Like phpMyAdmin shows a table, just a basic table structure with the name of the fields and all the records in that table.
Any help would be appreciated
This code show the a dinamic table with all the field and all the rows returned from a query...
This works for all pourpose you need
show all table rows
<?php
// list all the table in database
$result = mysql_query("show tables");
// show all the field with type, lenght,description of a specific table
$result = mysql_query("DESCRIBE table_name");
// show a specific tables row
$result = mysql_query("SELECT * FROM table_name");
if (mysql_num_rows($result)>0){
$r = mysql_fetch_array($result,MYSQL_ASSOC);
$table="<table><tr>";
$firstLine="<tr>";
foreach ($r as $k => $v){
$table .="<td>".$k."</td>";
$firstLine .="<td>".$v."</td>";
}
$table.="</tr>".$firstLine."</tr>";
while($r = mysql_fetch_array($result,MYSQL_ASSOC)){
$table.="<tr>";
foreach($r as $k => $v)
$table.="<td>".$v."</td>";
$table.="</tr>";
}
$table .="</table>";
echo $table;
}
?>