Hi,
I have data horizontally partitioned over several MySQL servers. After I connect and run a query on each server, I'd like to merge the results they give me and use that data in a loop to fill a table with data, reverse sorted by a PRIMARY KEY. I presume this would be done with arrays.
I'm still quite new to PHP and I'd like some help solving this problem.
Thank you.
Merging MySQL query results
Moderator: General Moderators
Re: Merging MySQL query results
Code: Select all
$result = array_merge($array1, $array2, $array3);
Re: Merging MySQL query results
You might be better off performing a UNION to combine all the different datasets into one at the database level. You can then apply ordering and grouping clauses on the entire dataset.
Re: Merging MySQL query results
Indeed, but:astions wrote:Code: Select all
$result = array_merge($array1, $array2, $array3);
1) How do I merge the entire result set and not just the first line?
2) How do I get this new array to do the same as mysqli_fetch_row in a loop?
The datasets are on different servers. Federated tables are not an option.pytrin wrote:You might be better off performing a UNION to combine all the different datasets into one at the database level. You can then apply ordering and grouping clauses on the entire dataset.
Re: Merging MySQL query results
I recommended array_merge assuming you already have all 3 complete result sets stored in arrays. You can use $record = array_shift($array); to pull a record off the array stack or you can loop through them with foreach(). Have a look at the array functions for details. Without knowing more that's about all I can tell you.
http://us2.php.net/manual/en/ref.array.php
http://us2.php.net/manual/en/ref.array.php