Optimizing a mysql_list_tables () ... ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rxsid
Forum Commoner
Posts: 82
Joined: Thu Aug 29, 2002 12:04 am

Optimizing a mysql_list_tables () ... ?

Post by rxsid »

hi all,

im trying to list each table in a db, then do a query on each table returned to display the results of each query on each table
there are 25 tables, and i get a minimum 500 hits to this code per day:

Code: Select all

//$connection already established
$result = mysql_list_tables($dbname);

//get tables
while ($table = mysql_fetch_row($result)) {

      $sql = "select a_field from $table[0]";
      $sql_result = mysql_query ($sql, $connection) or die("Couldnt execute query");

      //display the result - a single number
      if ($row = mysql_fetch_array($sql_result)) {
          do {
               $the_data = $row["a_field"];
         } while ($row = mysql_fetch_array($sql_result)); 
      }

} //END WHILE
is this expensive? how can i optimize this code?? :?:
Post Reply