我已经让Haversine 可以检索满足距离条件的行,但无法让Mysql COUNT() 函数工作。这是我的代码的一部分:
$query1 = "
SELECT COUNT(\"$table.*\") AS numrows1, outcodepostcodes.lat, outcodepostcodes.lng
,111.045* DEGREES(ACOS(COS(RADIANS($latpoint))
* COS(RADIANS(outcodepostcodes.lat))
* COS(RADIANS($longpoint) - RADIANS(outcodepostcodes.lng))
+ SIN(RADIANS($latpoint))
* SIN(RADIANS(outcodepostcodes.lat)))) AS distance
FROM $table
LEFT JOIN outcodepostcodes
ON UPPER(\"$table.postcode\")=outcodepostcodes.outcode
HAVING ROUND(distance,2) <= $choosedistn
ORDER BY rent $reihenach LIMIT $offset, $rowsPerPage
";
然后按如下方式处理 $queries:
$result1 = mysql_query($query1) or die('Error, query1 failed:' .mysql_error());
$result2 = mysql_query($query2) or die('Error, query2 failed:' .mysql_error());
$row1 = mysql_fetch_array($result1, MYSQL_ASSOC);
$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
$numrows1 = $row1['numrows1'];
$numrows2 = $row2['numrows2'];
我得到的 $numrows 为 NULL。非常感谢任何帮助。
最佳答案
这里的引号是错误的COUNT(\"$table.*\") AS numrows1
。
就这样吧
COUNT(`$table`.*) AS numrows1
关于mysql - 在 Mysql 中使用 Haversine 计算时无法使 COUNT() 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38556166/