I have an array called $restaurantArray
which contains a selection of restaurant id's.
Is there anyway I can execute a mysql query that will return rows if their id is equal to one of these restaurant ID's in the array?
Thanks.
I have an array called $restaurantArray
which contains a selection of restaurant id's.
Is there anyway I can execute a mysql query that will return rows if their id is equal to one of these restaurant ID's in the array?
Thanks.
You can use IN with your mysql query. Just implode the array $restaurantArray into the string, using comma as a delimiter; cover this string with brackets; and use the result string as input to the query. Something like
// uncomment if data needs to be sanitized
// $restaurantArray = array_map("mysql_real_escape_string", $restaurantArray);
$input = '(' . implode(',', $restaurantArray) . ')';
$query = "SELECT from foo WHERE id IN $input";