php - SQL query based on array -
this question has answer here:
- can bind array in() condition? 19 answers
i have array called $restaurantarray
contains selection of restaurant id's.
is there anyway can execute mysql query return rows if id equal 1 of these restaurant id's in array?
thanks.
you can use in mysql query. implode array $restaurantarray string, using comma delimiter; cover string brackets; , use result string input query. like
// uncomment if data needs sanitized // $restaurantarray = array_map("mysql_real_escape_string", $restaurantarray); $input = '(' . implode(',', $restaurantarray) . ')'; $query = "select foo id in $input";
Comments
Post a Comment