php - How to use array value in where clause in SQL -
i have array $rest_id
have 3 ids, when foreach , put in sql query there 1 value appears when debug it. here code.
$ids = array(); foreach ($rest_id $value) { $ids[] = $value->id; $nearest_rest = db::select("select *, (3956 * 2 * asin(sqrt( power(sin(( 28.5812674 - lat) * pi()/180 / 2), 2) +cos( 28.5812674 * pi()/180) * cos(lat * pi()/180) * power(sin(( 77.3181059 - lng) * pi()/180 / 2), 2) ))) distance restaurant_details id in ('" . implode("','",$ids) . "') having distance order distance asc limit 1"); dd($nearest_rest); }
i think need this, if want nearest restaurant out of 3 ids:
$ids = array(); foreach ($rest_id $value) { $ids[] = $value->id; } $nearest_rest = db::select("select *, (3956 * 2 * asin(sqrt( power(sin(( 28.5812674 - lat) * pi()/180 / 2), 2) +cos( 28.5812674 * pi()/180) * cos(lat * pi()/180) * power(sin(( 77.3181059 - lng) * pi()/180 / 2), 2) ))) distance restaurant_details id in ('" . implode("','",$ids) . "') having distance order distance asc limit 1"); dd($nearest_rest);
Comments
Post a Comment