Re: Basic Dual Query Combine into one question

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

 



On Thu, Jan 22, 2015 at 8:50 PM, dealTek <dealtek@xxxxxxxxx> 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?
>
>
Dave,

It sounds like you're being forced into the inefficient route for some
reason.  That said:  the array_merge should do what you need, IF the keys
in each array are unique.  From
http://php.net/manual/en/function.array-merge.php:

array array_merge ( array $array1 [, array $... ] )

Merges the elements of one or more arrays together so that the values of
one are appended to the end of the previous one. It returns the resulting
array.

If the input arrays have the same string keys, then the later value for
that key will overwrite the previous one. If, however, the arrays contain
numeric keys, the later value will not overwrite the original value, but
will be appended.

Values in the input array with numeric keys will be renumbered with
incrementing keys starting from zero in the result array.



Basically, you'll put the results from your first query in $everybodyCA and
the results of the second in $everybodyTX, then create a new array,
$everybodyCAandTX using array_merge.

Hope this helps!

Andy

[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