lundi 29 août 2016

Please assist with complex mysql query converting for use in Laravel 5

Here is my query.. I have tried several different ways to get the proper result while formatting for laravel 5, if anyone can assist with the proper format I would greatly appreciate it

  SELECT z.id, z.address, z.city, z.state, z.zip, 
    z.latitude, z.longitude, 
      (p.distance_unit 
        * DEGREES(ACOS(COS(RADIANS(p.latpoint)) 
        * COS(RADIANS(z.latitude)) 
        * COS(RADIANS(p.longpoint) - RADIANS(z.longitude)) 
        + SIN(RADIANS(p.latpoint)) 
        * SIN(RADIANS(z.latitude))))) AS distance 
  FROM locations AS z 
  JOIN ( 
    SELECT ? AS latpoint, 
           ? AS longpoint, 
           ? AS radius, 
           ? AS distance_unit 
    ) AS p 
  WHERE z.latitude 
    BETWEEN p.latpoint  - (p.radius / p.distance_unit) 
    AND     p.latpoint  + (p.radius / p.distance_unit) 
  AND   z.longitude 
    BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) 
    AND     p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) 
  ORDER BY distance 
  LIMIT ?

my variables are in order:

$latpoint
$longpoint
$radius
$distance_units
$limit



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bvCMi5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire