hi everyone. i want to list and show the table names in a database in a php page. how to do that? in phpmyadmin 'show tables' works in query window. bt showing it through a php script i think i would have to SELECT?

SHOW TABLES is the actual query.

thanks for replying pritaeas...bt how can i show the list in a page through php?

Hi,

I just borrowed this from someone...please see the script's credit on top. This might be more than what you need..if it just table names that you want, then just remove the bottom part of the script.

<?php
/****************
* File: displaytables.php
* Date: 1.13.2009
* Author: design1online.com
* Purpose: display all table structure for a specific database
****************/

//connection variables

$host = "localhost";
$database = "database";
$user = "user";
$pass = "password";

//connection to the database
mysql_connect($host, $user, $pass)
or die ('cannot connect to the database:' . mysql_error());

//select the database
mysql_select_db($database)
or die ('cannot select database:' . mysql_error());

//loop to show all the tables and fields
$loop = mysql_query("SHOW tables FROM $database")
or die ('cannot select tables');

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

echo "
<table cellpadding=2 cellspacing=2 border=0 width=75%>
<tr bgcolor=#666666>
<td colspan=5><center><b><font color=#FFFFFF>” . $row[0] . “</font></center></td>
</tr>
<tr>
<td>Field</td><td>Type</td><td>Key</td><td>Default</td><td>Extra</td>
</tr>";

$i = 0;

$loop2 = mysql_query("SHOW columns FROM " . $row[0])
or die ('cannot select table fields');

while ($row2 = mysql_fetch_array($loop2))
{
echo "<tr ";
if ($i % 2 == 0)
echo "bgcolor=#CCCCCC";
echo "><td>". $row2[0] . "</td><td>". $row2[1] . "</td><td>" . $row2[2] . "</td><td>" . $row2[3] . "</td><td>" . $row2[4] . "</td></tr>";
$i++;
}
echo "</table><br/><br/>";

}
?>

thanks buddy....this will do...

you are very much welcome :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.