我让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
";
然后按以下方式处理$查询:
$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。非常感谢任何帮助。
答案 0 :(得分:1)
此处的引号错误COUNT(\"$table.*\") AS numrows1
。
像这样做
COUNT(`$table`.*) AS numrows1