Skip to content

Instantly share code, notes, and snippets.

@geggleto
Forked from jersobh/select.php
Last active May 31, 2016 15:34
Show Gist options
  • Save geggleto/ee0933cab2ac9263fc9e172d1e25ed1b to your computer and use it in GitHub Desktop.
Save geggleto/ee0933cab2ac9263fc9e172d1e25ed1b to your computer and use it in GitHub Desktop.
$near = "SELECT c.id, c.name, c.email, c.phone, c.logo, c.banner, c.description, cl.lat, cl.lng,
ACOS( SIN( RADIANS( cl.lat ) ) * SIN( RADIANS( '$lat' ) ) + COS( RADIANS( cl.lat ) )
* COS( RADIANS( '$lat' )) * COS( RADIANS( cl.lng ) - RADIANS( '$lng' )) ) * 6380 AS distance
FROM CLIENT_LOCATION cl
INNER JOIN CLIENT c
on cl.client_id = c.id
WHERE
ACOS( SIN( RADIANS( cl.lat ) ) * SIN( RADIANS( ? ) ) + COS( RADIANS( cl.lat ) )
* COS( RADIANS(? )) * COS( RADIANS( cl.lng ) - RADIANS( ? )) ) * 6380 < 10
ORDER BY distance ASC";
$foodtrucks = array();
$stmt = $this->db->prepare($near);
$stmt->execute([$lat, $lat, $lng]);
$foodtrucks = $stmt->fetchAll();
return $response->withJson($foodtrucks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment