基本上我有一个在经度和纬度中设置的数据库。我已经尝试了几个小时来解决我遇到的 MySql 问题,但我找不到我的错误。这是我收到的错误:
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 '€“ longitude) * PI() / 180))* 180 / PI()) * 60 * 1.1515)*1.609344) AS distance' at line 1
这里是 MySql 数据库查询,用于获取 long 和 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());
拜托拜托拜托了!!!
最佳答案
发生错误的看起来像减号的字符似乎不是减号。也许您使用 Word(或类似的“有帮助的”编辑器)来构建查询,并且它替换了一个“智能”版本的减号,例如破折号?
我用适当的减号替换了那个字符,查询成功了。
关于尝试从经度和纬度获取距离时出现Mysql错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12394978/