Question

I am getting this error from mysql:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long) *pi()/180 / 2), 2) ))as distance FROM wp_places_locator dest having dista' at line 1

when using this query:

set @orig_lat=121.9763; set @orig_lon=37.40445;
set @dist=10;
SELECT *,3956 * 2 * ASIN(SQRT(POWER(SIN((@orig_lat -abs(lat)) * pi()/180 / 2),2) + COS(@orig_lat * pi()/180 ) * COS(abs(lat) *pi()/180) * POWER(SIN((@orig_lon - long) *pi()/180 / 2), 2) ))as distance
FROM wp_places_locator dest having distance < @dist
ORDER BY distance limit 10\G;

the code is adapted from here: http://arubin.org/files/geo_search.pdf to search my database for geolocation coordinates near coordinates it will recieve and sort them in order of distance from the recieved coordinates. any help would be really appreciated.

Was it helpful?

Solution

The word long is a reserved word. You can find the list of words here.

This means that you need to escape the name, typically using backticks.

Better yet, don't used reserved words as identifiers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top