I'm trying to run a SQL query to search for a term and a users location. I need help to search my database for locations near a user with the description of 'X'. The users location (lat, long) is drawn when they click 'find' on a form for 'X'.
Individually each query works fine. I can find all with a specific %search_term% using:
SELECT * FROM `table_name` WHERE `column_name` LIKE '%search_term%'
and also find all the locations from the distant of the user using:
SELECT *, (
3959 * acos (
cos ( radians($lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($long) )
+ sin ( radians($lat) )
* sin( radians( lat ) )
)
) AS distance
FROM locations
HAVING distance < 50
ORDER BY distance
LIMIT 0 , 20;
but together I receive an error #1064.
This is the query:
SELECT * FROM `table_name` WHERE `column_name` LIKE '%search_term%' AND
*, (
3959 * acos (
cos ( radians($lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($long) )
+ sin ( radians($lat) )
* sin( radians( lat ) )
)
) AS distance
FROM locations
HAVING distance < 50
ORDER BY distance
LIMIT 0 , 20;
LIMIT 0
? Doesn't that mean return nothing?LIMIT 0 OFFSET 20
(i.e. returning no rows, starting from row 20). I don't really understand the syntax or why that would be useful; have you tried just withLIMIT 10
or something?