If a $request body was passed in with the categories 9,1,7 and I try to do the following it only will return the categories with ID 9
$categories = implode('","',$request->categories);
$statement = <<<'ENDSTATEMENT'
SELECT
locations.name,
locations.id,
locations.lon,
locations.lat,
locations_categories.category_id as catId,
locations_categories.location_id as locId,
haversine(?,?,locations.lon,locations.lat) as distance
FROM locations_categories, locations
WHERE locations.id = locations_categories.location_id
AND locations_categories.category_id IN (?)
ORDER BY `distance` ASC
ENDSTATEMENT;
$locations = DB::select($statement, array($request->lon, $request->lat, $categories));
But if if I was to do
AND locations_categories.category_id IN ("9","1","7")
Instead of passing the $categories variable in it returns all of the categories.
Why would it work for the hard coding but not passing the parameters in?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community