Posted by larry on 12/17/06 06:08
kenoli wrote:
> I am doing a compound lookup by deriving person_id values for a query
> from various tables by selecting arrays of person_id values that meet
> my criteria from those tables. I am ending up with a query whose logic
> would be something like:
>
> SELECT * FROM tbl_person WHERE first_name = "John" AND (person_id = '2'
> OR person_id = '4' OR person_id = '6' OR person_id = '10') AND
> (person_id = '1' OR person_id = '4' OR person_id = '10' OR person_id =
> '20') AND (person_id = '4' OR person_id = '7' OR person_id = '6' OR
> person_id = '10');
>
> I have the id values from the lookup tables in separate arrays. I'm
> thinking that the equivalent to the above query would be an array made
> up only of values that show up in all three arrays. I could then
> create a simpler query like:
>
would
array_intersect($array1,$array2,$array3)
work?
Look up array_intersect on php.net to get more insight on variatons,
refinements
http://us2.php.net/manual/en/function.array-intersect.php
FYI - Programming PHP (O'Reiley) does a great job of covering array
functions as well as most other PHP functions.
Navigation:
[Reply to this message]
|