Re: Merge result set of query?

From: Date: Wed, 09 Mar 2005 21:38:46 +0000
Subject: Re: Merge result set of query?
References: 1 2 3 4  Groups: php.db 
Request: Send a blank email to php-db+get-38841@lists.php.net to get a copy of this message
Martin Norland wrote:
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)) {
while reading I thought, would this: while (($row = mysql_fetch_row($result)) || ($row = mysql_fetch_row($result2))) { // just do it. √ } .. work (due to shortcircuiting)? and how ugly is it?
    // foo
}
...

« previous php.db (#38841) next »