views:

39

answers:

1

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');
 }
A: 

It would be better to do something like this:

<?php
$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.

BraedenP
almost worked, this got it going$res = mysql_query("SHOW TABLES FROM table");$tables = array();while($row = mysql_fetch_array($res, MYSQL_NUM)) {$tables[] = "$row[0]"; $domain = $row[0]; include ('code.php');}
Yeah, I wasn't sure exactly what you were trying to do, so I tried to guess. Glad you got it working though.
BraedenP