Click to See Complete Forum and Search --> : How do i display all the table names in a database?
rapidz
12-28-2006, 03:28 PM
There is a database called "nickm_results". There are many tables inside this database.
What i want to be able to do, is list all the table names in the database.
Is there a way to do this?
any help would be much appreciated.
thanks in advance.
rapidz.
NightShift58
12-28-2006, 03:57 PM
<?php
$sql = "SHOW TABLES LIKE *";
$qry = mysql_query($sql);
IF ($qry) :
WHILE ($row = mysql_fetch_array($qry)) :
// process as you would any query result
ENDWHILE;
ENDIF;
?>
rapidz
12-28-2006, 04:14 PM
that didn't work. i need to just be able to output the table names from a database.
NightShift58
12-28-2006, 04:25 PM
That's what the above will do for you. In case of doubt, please check: http://dev.mysql.com/doc/refman/4.1/en/show-tables.html
What I didn't include in my post is the part where you connect and select the database, otherwise the sample is good to go... Obviously, you'll have to add your echo/print statements where and how you want them - in case, that's what you mean about the script not working.
rapidz
12-28-2006, 04:31 PM
what variable do i echo? $qry ???
NightShift58
12-28-2006, 04:37 PM
<?php
include "dbconnect.inc.php";
$sql = "SHOW TABLES LIKE *";
$qry = mysql_query($sql);
IF ($qry) :
WHILE ($row = mysql_fetch_array($qry)) :
print $row[0] . "<br>";
ENDWHILE;
ENDIF;
?>I'm not sure what information - if any - besides the table name you want to display and how you want to format the display. The above will give you a list of tables in the database you selected during the connection process.