Page 1 of 1

Query Issues

Posted: Mon Sep 22, 2008 1:28 pm
by Weasel5-12
I've got a question about a selection query, where i need to select a set of values based on parameters stored in an array.

Code: Select all

$query = "SELECT * FROM ingredientlist WHERE ingredientID='$ingredientID[]'";

i'd like the output query to resemble something similar to.. SELECT * FROM ingredientlist WHERE ingredientID='$ingredientID[1]' && ingredientID='$ingredientID[2]' && ingredientID='$ingredientID[3]' and so on...

how do i loop through this? i can't figure it out for the life of me..

thankyou very much for any replies

Re: Query Issues

Posted: Mon Sep 22, 2008 1:49 pm
by califdon
Sounds like you want to use the OR operator:
...WHERE ingredientID='$ingredientID[1]' OR ingredientID='$ingredientID[2]' OR ingredientID='$ingredientID[3]'
or perhaps the IN operator:
...WHERE ingredientID IN('$ingredientID[1]', '$ingredientID[2]', '$ingredientID[3]')

Re: Query Issues

Posted: Tue Sep 23, 2008 1:53 pm
by Weasel5-12
something like that, but i dont know how long the array will be though..

so how can i loop through it...?

Re: Query Issues

Posted: Tue Sep 23, 2008 5:25 pm
by califdon
Weasel5-12 wrote:something like that, but i dont know how long the array will be though..

so how can i loop through it...?

Code: Select all

foreach($ingredientID as $ing) {
    ....
}