Re: Merge result set of query?

From: Date: Wed, 09 Mar 2005 21:25:23 +0000
Subject: Re: Merge result set of query?
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-38840@lists.php.net to get a copy of this message
ioannes wrote:
My first attempt was to use $result=array_merge($result1,$result2) - doesn't work. 'not a valid resource' I have two databases with different connections, so MySQL UNION query would not work. How do I merge the result set of the queries in that case?
You're going to have to merge the results within PHP. "not a valid resource" is an error you get when you try to read from a result set and what you pass it isn't a resource for a result set. I think you're doing something along the lines of: $result1 = query_database_one($somequery); $result2 = query_database_two($someotherquery); $result = array_merge($result1, $result2); while (mysql_fetch_row($result)) { // foo } ... Which won't work on any level. mysql_fetch_row takes a resource, it's a pointer to give the database to retrieve the row. When you do your query to the database, the database does the query but doesn't return the full result - instead it just returns a resource to the result, so you can get it as you need it. I suggest you start from that information and work forward. cheers, -- - Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.

« previous php.db (#38840) next »