Page 1 of 1

Optimizing a mysql_list_tables () ... ?

Posted: Wed Dec 04, 2002 3:24 pm
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?? :?: