添加更多条件以在 mysql - google 地图中查找附近的地点
Adding few more conditions to find nearby places in mysql - google maps
我正在尝试使用我在 google 的文档 here
中找到的解决方案找到附近的地方
问题是我想在搜索中添加更多过滤器
原解
$sql2 = "SELECT *, ( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance FROM " . $table . " HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20;
我想让它在上面的语句中添加这个过滤器
SIZE between $firstrange and $secondrange"
我试过了,但没有提供所需的结果
$sql2 = "SELECT *, ( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance FROM " . $table . " HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20 and SIZE between $firstrange and $secondrange";
我在这里做错了什么?我不能通过在它们之间放置 AND
来添加这些条件吗?
当然可以使用 AND 添加条件,但必须将它们添加到 WHERE 或 HAVING 子句中,而不是在语句的末尾:
SELECT *,
( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance
FROM " . $table . "
WHERE SIZE between $firstrange and $secondrange
HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20 ;
(我想 SIZE 是你 table 中的一列)
我正在尝试使用我在 google 的文档 here
中找到的解决方案找到附近的地方问题是我想在搜索中添加更多过滤器
原解
$sql2 = "SELECT *, ( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance FROM " . $table . " HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20;
我想让它在上面的语句中添加这个过滤器
SIZE between $firstrange and $secondrange"
我试过了,但没有提供所需的结果
$sql2 = "SELECT *, ( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance FROM " . $table . " HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20 and SIZE between $firstrange and $secondrange";
我在这里做错了什么?我不能通过在它们之间放置 AND
来添加这些条件吗?
当然可以使用 AND 添加条件,但必须将它们添加到 WHERE 或 HAVING 子句中,而不是在语句的末尾:
SELECT *,
( 3959 * acos( cos( radians(" . $row1['tubeLan'] . ") ) * cos( radians( mapLan ) ) * cos( radians( mapLon ) - radians(" . $row1['tubeLon'] . ") ) + sin( radians(" . $row1['tubeLan'] . ") ) * sin( radians( mapLan ) ) ) ) AS distance
FROM " . $table . "
WHERE SIZE between $firstrange and $secondrange
HAVING distance < 2500 ORDER BY distance LIMIT 0 , 20 ;
(我想 SIZE 是你 table 中的一列)