Skip to content

Instantly share code, notes, and snippets.

@jersobh
Created May 31, 2016 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jersobh/2048f454e4608e1050dc613180596e69 to your computer and use it in GitHub Desktop.
Save jersobh/2048f454e4608e1050dc613180596e69 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( '$lat' ) ) + COS( RADIANS( cl.lat ) )
* COS( RADIANS( '$lat' )) * COS( RADIANS( cl.lng ) - RADIANS( '$lng' )) ) * 6380 < 10
ORDER BY distance ASC";
//
// $foodtrucks = $this->db->query($near);
//
$foodtrucks = array();
$stmt = $this->db->prepare($near);
$stmt->execute();
$foodtrucks = $stmt->fetchAll();
$foodtrucks = json_encode($foodtrucks);
//echo json_encode($foodtrucks);
$response->withJson($foodtrucks);
$response = $response->withHeader('Content-type', 'application/json');
$response = $response->withStatus(200);
return $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment