I have a table containing a list of events and the lat/lon where they occurred. I am looking to get all of the events from the table within 1KM of a lat/lon coordinate submitted by the user.
My query works, but gets ALL results in the table, sorting them by distance from lon/lat ascending. I would like to filter the results of my query with WHERE distance_in_km < 1. The issue is that distance_in_km was created within the query, just appending the WHERE clause as described above wouldn't work.
I'm thinking nested IF, but can't wrap my head around it!
SELECT id, latitude, longitude, 111.320 * DEGREES(ACOS(COS(RADIANS(".$lookup->latitude."))
* COS(RADIANS(latitude))
* COS(RADIANS(longitude) - RADIANS(".$lookup->longitude."))
+ SIN(RADIANS(".$lookup->latitude."))
* SIN(RADIANS(latitude))))
AS distance_in_km
FROM uk_events
ORDER BY distance_in_km ASC
LIMIT 0,500;
So to explain logically what I'd 'like' to happen, imagine [[[this]]] would work:
AS distance_in_km
FROM uk_events
[[[WHERE distance_in_km <1.01]]]
ORDER BY distance_in_km ASC
LIMIT 0,500;
Thanks for any help! Arbiter
Aucun commentaire:
Enregistrer un commentaire