MySQL 半正矢公式中的语法错误

发布于 2024-11-07 03:11:37 字数 1456 浏览 3 评论 0原文

我在下面的代码中遇到令人沮丧的 MySql 语法错误。实际错误是:

SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 9 行的“JOIN storetable ON Pricelist.storecode = storetable.storecode JOIN itemlist ON”附近使用的正确语法”

附加信息:此代码基于 Google Maps Php/MySql 示例: http://code.google.com/apis/maps/articles/phpsqlsearch.html

在尝试添加 JOIN 语句之前,我能够让这段代码正常工作。

$query = sprintf("SELECT storetable.storeaddress, 
                         storetable.storename, 
                         storetable.lat, 
                         storetable.lng,
                         ( 3959 * acos( cos( radians('%s') ) * 
                         cos( radians( storetable.lat ) ) *                              cos(radians(storetable.lng)  - radians('%s') ) + 
                         sin( radians('%s') ) * sin( radians( storetable.lat ) ) ) ) AS distance 
                    FROM pricelist 
                  HAVING distance < 25 
                ORDER BY distance 
                   LIMIT 0 , 20,
                    JOIN storetable ON pricelist.storecode = storetable.storecode
                    JOIN itemlist ON pricelist.upccode = itemlist.upccode",
                 mysql_real_escape_string($latitude),
                 mysql_real_escape_string($longitude),
                 mysql_real_escape_string($latitude));

I'm getting a frustrating MySql syntax error in my code below. The actual error is:

SQLSTATE[42000]: Syntax error or access violation: 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 ' JOIN storetable ON pricelist.storecode = storetable.storecode JOIN itemlist ON' at line 9"

Additional info: This code based on Google Maps Php/MySql example: http://code.google.com/apis/maps/articles/phpsqlsearch.html

I was able to get this code to work fine before I tried to add the JOIN statements.

$query = sprintf("SELECT storetable.storeaddress, 
                         storetable.storename, 
                         storetable.lat, 
                         storetable.lng,
                         ( 3959 * acos( cos( radians('%s') ) * 
                         cos( radians( storetable.lat ) ) *                              cos(radians(storetable.lng)  - radians('%s') ) + 
                         sin( radians('%s') ) * sin( radians( storetable.lat ) ) ) ) AS distance 
                    FROM pricelist 
                  HAVING distance < 25 
                ORDER BY distance 
                   LIMIT 0 , 20,
                    JOIN storetable ON pricelist.storecode = storetable.storecode
                    JOIN itemlist ON pricelist.upccode = itemlist.upccode",
                 mysql_real_escape_string($latitude),
                 mysql_real_escape_string($longitude),
                 mysql_real_escape_string($latitude));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦初醒的夏天 2024-11-14 03:11:37

JOIN 位于错误的位置 - 它们位于 FROM 子句之后、WHERE 子句之前 - 使用:

$query = sprintf("SELECT storetable.storeaddress, 
                         storetable.storename, 
                         storetable.lat, 
                         storetable.lng,
                         ( 3959 * acos( cos( radians('%s') ) * 
                         cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + 
                         sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance 
                    FROM pricelist 
                    JOIN storetable ON pricelist.storecode = storetable.storecode
                    JOIN itemlist ON pricelist.upccode = itemlist.upccode
                  HAVING distance < 25 
                ORDER BY distance 
                   LIMIT 0, 20",
                 mysql_real_escape_string($latitude),
                 mysql_real_escape_string($longitude),
                 mysql_real_escape_string($latitude));

JOINs were in the wrong place - they come after the FROM clause, before the WHERE clause - Use:

$query = sprintf("SELECT storetable.storeaddress, 
                         storetable.storename, 
                         storetable.lat, 
                         storetable.lng,
                         ( 3959 * acos( cos( radians('%s') ) * 
                         cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + 
                         sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance 
                    FROM pricelist 
                    JOIN storetable ON pricelist.storecode = storetable.storecode
                    JOIN itemlist ON pricelist.upccode = itemlist.upccode
                  HAVING distance < 25 
                ORDER BY distance 
                   LIMIT 0, 20",
                 mysql_real_escape_string($latitude),
                 mysql_real_escape_string($longitude),
                 mysql_real_escape_string($latitude));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文