drryyiuib43562604
2018-05-17 11:59
浏览 63
已采纳

MySQL#1064错误的位置查找器[关闭]

I'm trying to find the 10 entries that are closest to the user with the following search:

  $data_query = mysqli_query($db, "SELECT *
  111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
             * COS(RADIANS(latitude))
             * COS(RADIANS(longpoint) - RADIANS(longitude))
             + SIN(RADIANS(latpoint))
             * SIN(RADIANS(latitude)))) AS distance_in_km
 FROM merchants
 JOIN (
 SELECT  33.889676  AS latpoint,  151.193024 AS longpoint
) AS p ON 1=1
ORDER BY distance_in_km
LIMIT 15");

However I'm getting the following error:

#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 '111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
             * COS(RADIANS(la' at line 2

I tried changing SELECT * to SELECT latitude, longitude (with `` but Stack Overflow keeps messing up syntax) but it's not doing much.

I'm new to PHP and MySQL so I'm feeling pretty out of depth as to what could be going wrong here.

Cheers :)

图片转代码服务由CSDN问答提供 功能建议

我正在尝试通过以下搜索找到最接近用户的10个条目:

  $ data_query = mysqli_query($ db,“SELECT * 
 111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
 * COS(RADIANS(纬度))
 * COS  (RADIANS(长点) -  RADIANS(经度))
 + SIN(RADIANS(latpoint))
 * SIN(RADIANS(纬度))))AS distance_in_km 
 FROM商家
 JOIN(
 SELECT 33.889676 AS latpoint,  151.193024 AS longpoint 
)AS p ON 1 = 1 
ORDER by distance_in_km 
LIMIT 15“); 
   
 
 

但是我收到以下错误:

 #1064  - 您的SQL语法出错; 检查与MySQL服务器版本对应的手册,以便在'111.045 * DEGREES附近使用正确的语法(ACOS(COS(RADIANS(latpoint))
 * COS(RADIANS(la'在第2行
  <  / pre> 
 
 

我尝试将 SELECT * 更改为 SELECT纬度,经度(使用``但Stack Overflow不断弄乱语法)但它没有做 很多。

我是 PHP MySQL 的新手,所以我对于可能会发生什么感觉非常深入 这里错了。

干杯:)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufan2541 2018-05-17 12:04
    已采纳

    If you want also select everything, then add comma after first *: SELECT *, 111.045 ...

    If not, then remove first *

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题