爲什麼這個查詢不起作用?子查詢計算錯誤?
$query = ("SELECT * FROM
(SELECT *, (
(((endingLatitude - " . $h . ")(endingLatitude - " . $h . "))
/" . pow($r1, 2) . ")
+
((endingLongitude - " . $k . ")(endingLongitude - " . $k . "))
/" . pow($r2, 2) . "
) AS point2
FROM (SELECT *, ((
(
((startingLatitude - " . $h . ")(startingLatitude - " . $h . "))
/" . pow($r1, 2) . ")
+
((startingLongitude - " . $k . ")(startingLongitude - " . $k . "))
/" . pow($r2, 2) . "))
AS point1
FROM (SELECT * FROM trips WHERE distance >='" . ($distance * .25) . "') as query1)
as query2) as query3 WHERE point1 <= 1 AND point2 <= 1 LIMIT 0 , 10;");
$result = mysqli_query($con, $query);
$ h和$ k分別是橢圓的x和y座標。我使用公式here來計算兩點(startingLat,startingLong)和(endingLat,endingLong)是否位於垂直高度$ r1和水平高度$ r2的橢圓內。我還將我搜索的行限制爲距離單元格值大於$ distance * .25的行。
我認爲這可能與括號錯誤有關,或與我子查詢/執行計算的方式有關。
使用
die(mysqli_error($con));
返回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 '(endingLatitude - 36.9564753)) /796.842964388) + ((endingLongitud' at line 3
你做了什麼錯誤? –
@anantkumarsingh失敗'if(!$ result)'然後打印,'$ result = mysqli_query($ con,$ query);' –
把'$ result = mysqli_query($ con,$ query)或者死(mysqli_error($ con));'並檢查你所得到的真實錯誤。謝謝。 –