Jump to content

Show table and table values from a database


peuge

Recommended Posts

Hi, I am using PHP5 and am wandering how I can echo all the tables and their field names in a selected database.

$tables = array();

$rows = mysql_query("SHOW TABLES FROM $dbinfo");

while ($row = mysql_fetch_array($rows)) {

$tables[] = $row[0];

}

print_r($tables);

 

The above just shows the tables in the database but not the fields in that table.

Could anyone please tell me how I would go about doing this.

Thanks

Peuge

<?php
$result = mysql_query("SHOW COLUMNS FROM sometable");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        print_r($row);
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.