Mysql error while trying to get distance from long and lat

Basically, I have a database that is configured in Longitude and Latitude. I’ve been trying for several hours to fix the problem with MySql and I can’t find my error. Here is the error I get:

You have an error in the SQL syntax; check the manual that matches the version of your MySQL server for the correct syntax used near longitude longitude) * PI () / 180)) * 180 / PI ()) * 60 * 1.1515) * 1.609344) AS distance 'at line 1

Here is the MySql database query to get the distances from long and lat:

$res = mysql_query("SELECT *, (((ACOS(SIN(".$latitude." * PI() / 180) * SIN(latitude * PI() / 180) + COS(".$latitude." * PI() / 180) * COS(latitude * PI() / 180) * COS((".$longitude." – longitude) * PI() / 180))* 180 / PI()) * 60 * 1.1515)*1.609344) AS distance") or die(mysql_error()); 

Please, please help !!!

+4
source share
2 answers

The minus sign search symbol for which an error occurs is not a minus sign. Perhaps you used Word (or a similar "useful" editor) to build the query, and it replaced the "smart" version of the minus sign, for example en-dash?

I replaced this character with the corresponding minus sign and the request worked.

+1
source

I'm not sure why you are doing SELECT *, and you have no FROM . Remove *, from the query, or add FROM and the table from which you are extracting data.

0
source

Source: https://habr.com/ru/post/1433879/


All Articles