我在下面的代碼中收到令人沮喪的MySql語法錯誤。實際的錯誤是:Haversine公式中的MySQL語法錯誤
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"
附加信息:基於谷歌地圖的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));
我不知道MySQL的,但爲什麼你使用'ORDER BY'加入之前? – 2011-05-13 04:56:58
@taspeotis:你是對的。正如OMG Ponies指出的那樣,ORDER BY在JOINS之後。 – 2011-05-13 05:44:20