Reputation: 931
I am trying to get nearby place using a solution I found on google's documents here
The problem is I want to add few more filters in search
Original solution
$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;
What I want it to add this filter in the above statement
SIZE between $firstrange and $secondrange"
I tried this but didn't provide the required result
$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";
What am I doing wrong here? Can't I add these conditions by just putting AND
between them?
Upvotes: 0
Views: 54
Reputation: 146
sure you can add conditions using AND, but you have to add them to your WHERE or HAVING clause, not at the end of the statement:
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 ;
(i suppose SIZE is a column in your table)
Upvotes: 1