How would I go on to do these mysql_querys mysql_query("SELECT * FROM my_table_1"); mysql_query("SELECT * FROM my_table_2"); mysql_query("SELECT * FROM my_table_3"); mysql_query("SELECT * FROM my_table_4"); ..and put all the results in a array and echo that array..?
$tables = array('my_table_1', 'my_table_2', 'my_table_3', 'my_table_4'); $result_array = array(); foreach ($tables as $table) { $sql = "select * from {$table}"; $st = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_row($st)) $result_array[] = $row; } echo "<table border='1'>"; foreach ($result_array as $row) echo "<tr><td>" . join("</td><td>", $row) . "</td></tr>"; echo "</table>"; PHP:
If the tables are large, running scripts like this use up a lot of memory. It also increases overhead and execution time by a lot. I would look into using UNION http://dev.mysql.com/doc/refman/5.0/en/union.html
If the tables are large, using UNION will take up more RAM because the result set will be larger. Although I could have used a mysql_free_result() in the loop... The original request seems a bit wonky to me, in almost 15 years of using PHP I've never seen a reason to do that.