Re: Merge result set of query?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux