Page 1 of 1

Put multiple querys in array

Posted: Tue Jan 26, 2010 5:30 am
by lammspillning
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..?

Re: Put multiple querys in array

Posted: Tue Jan 26, 2010 10:55 am
by JakeJ
Assuming they all contain similar elements, try using a UNION query.

$qry = mysql_query("(SELECT * FROM table1) UNION (SELECT * FROM table2) UNION (SELECT * FROM table3)");
$results = mysql_fetch_array($qry);

Then you have your array!

***Here's another thought: I don't know what your data structure is like, but if you have multiple tables with similar data, I suspect it's not normalized properly. It might all belong in one table.