user176213 user176213 - 8 months ago 75
PHP Question

mysql_list_tables into foreach array?

Is it possible to list my tables into a foreach array?

current code.

$browsers = array ("site1", "site2", "site3");
foreach($browsers as $browser)
$domain = $browser;
include ('code.php');


It would be better to do something like this:

$db_name = "your_db_name";
$result = mysql_query("SHOW TABLES FROM $db_name");

while($array = mysql_fetch_array($result)){
    echo $array[0];
    //Or do other stuff with the table name

That will get a list of the tables in the DB, put them into an array, recurse through the array, and echo the names.

Of course, before you run this, you have to use mysql_pconnect() to connect to the database.