Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Vik Rubenfeld
August 20, 2007, 9:32 pm
rate this thread
that contains all the results from both mySQL queries.
My question is, how do you get all the resulting items from both
databases into one single, sorted list, to present to the user?
I guess one way would be, to use PHP to copy all the results from each
database, into a PHP array, and then sort it. Is that how this kind of
thing is usually done?
Thanks in advance to all for any info.
Re: Best Way to Combine Results from 2 mySQL Searches, into One Sorted List?
I'm curious about the data/tables, it might be possible to do all this o=
a MySQL level instead of PHP, which would usually be better.
$list = array();
$r1 = mysql_query("Enter query one here");
while($row = mysql_fetch_assoc($r1)) $list = $row;
$r2 = mysql_query("Enter query two here");
while($row = mysql_fetch_assoc($r2)) $list = $row;
$fieldname = 'foo'; //<- enter the fieldname to sort by
usort($list, create_function('$a,b',"if($a[''] =3D =
$b['']) return 0; return $a[''] > =
$b[''] ? 1 : -1;");
The database software is optimised for this kind of stuff, so if it can =
done there that would be highly preferable.