I'm looking for a SQLite query which will return values that are great or less than 0.014763 for the lng and 0.008830 for the lat. I'm using the following code...
$latupp = $_REQUEST['currlat'] + 0.008830;
$latlow = $_REQUEST['currlat'] - 0.008830;
$lngupp = $_REQUEST['currlng'] + 0.014763;
$lnglow = $_REQUEST['currlng'] - 0.014763;
$q=mysql_query("SELECT * FROM `tweets`
WHERE `lat` > $latlow AND
`lat` < $latupp OR
`lng` > $lnglow AND
`lng` < $lngupp;") or die(mysql_error());
But it's returning incorrect results e.g results greater or less than 0.1441209. I can't quite figure out why. does anyone have any suggestions?
Perhaps...
$q=mysql_query("SELECT * FROM `tweets`
WHERE `lat` > $latlow AND
`lat` < $latupp AND
`lng` > $lnglow AND
`lng` < $lngupp;") or die(mysql_error());
That should work:
$latupp = $_REQUEST['currlat'] + 0.008830;
$latlow = $_REQUEST['currlat'] - 0.008830;
$lngupp = $_REQUEST['currlng'] + 0.014763;
$lnglow = $_REQUEST['currlng'] - 0.014763;
$q=mysql_query("SELECT * FROM `tweets`
WHERE `lat` BETWEEN $latlow AND $latupp
AND
`lng` BETWEEN $lnglow AND $lngupp;") or die(mysql_error());
Maybe you need parenthesis to separate the first and second part (Can't test it here).
You made a little mistake by connecting the lat and the long constraint with an "OR". Your command says:
Give me all records which have:
OR
OR BOTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With