Merge two mysql_query results

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
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Merge two mysql_query results

Post by davidhopkins »

Hello !

In my code i generate two mysql_query results as shown

Code: Select all

       $Result = mysql_query( $Query );
       $SecondResult = mysql_query( $LabQuery );
I need to then merge these into one array to send back as a return

Both mysql queries have the same data in them in terms of database fields, instructionType, priceCode, price

Could someone help me please

Thanks

David
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Merge two mysql_query results

Post by Celauran »

Could you not use a multidimensional array?

$array['table1']['foo']
$array['table1']['bar']
$array['table2']['foo']
etc.
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: Merge two mysql_query results

Post by davidhopkins »

Im sorry im not sure how i would implement that . .
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Merge two mysql_query results

Post by AbraCadaver »

Use a UNION query. How it is structured will depend on if you have a WHERE clause, ORDER BY etc... [text]SELECT * FROM table1 UNION SELECT * FROM table2[/text]
http://dev.mysql.com/doc/refman/5.0/en/union.html
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply