0

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.

sark9012
  • 5,485
  • 18
  • 61
  • 99

1 Answers1

1

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";
didierc
  • 14,572
  • 3
  • 32
  • 52
Ankesh
  • 56
  • 1
  • 7