Re: Basic Dual Query Combine into one question

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

 



dealTek wrote:

> Hi all, (newbie question)
> 
> - let's say, (for some other reasons I'll skip here) I needed to do
> two separate queries to the same mysql contacts table (rather than
> one more elegant combined one)
> 
> 1 - find everybody from California 
> 2 - find everybody from Texas
> 
> Then – I would like to combine both of these queries into some kind
> of an array that I could loop through and display after sorting by
> last name
> 
> Q: I am curious the best way to combine the 2 separate queries into 1
> afterwards?

You can't combine 2 separate queries afterwards, but you could combine
their results.  How to retrieve the results depends on the database
library -- PDO offers PDOStatement::fetchAll() which can return an array
of records or objects.  You can use array_merge() to merge both arrays,
and usort() for sorting the merged array.

However, as others have already pointed out, it is preferable to use a
single query if possible.

-- 
Christoph M. Becker


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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux