PDA

Click to See Complete Forum and Search --> : [RESOLVED]How to output tablenames in specific databae using php


tony007
Oct 17th, 2007, 05:38 AM
hi all. Could any one show me how to display table names of a specific database using php? I tried the following but didn't output any thing!!

<?php

$server = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "?????"; // MySQL password
$dbname = "kingkong"; // MySQL db name

$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = "SHOW TABLES FROM kingkong ";

$fp = fopen("query.txt", "w");
fwrite($fp, $sql);
fclose($fp);
$result = mysql_query( $sql );

while($row = @mysql_fetch_array($result)) {

?>
<?php echo $row["tables"] ?>

<?

}

?>

the182guy
Oct 27th, 2007, 12:06 PM
'tables' isn't the field name that is returned by SHOW TABLES it's 'Tables_in_DBNAME'

so use $row[0]; or $row['Tables_in_kingkong'];

tony007
Oct 27th, 2007, 12:09 PM
thanks that $row[0] fixed it!