fraser5002 Posted April 4, 2010 Share Posted April 4, 2010 Hi, Can anyone let me know what is wrong with this SQL query i am getting an error saying my argument is not valid // // $query_accommodation="SELECT * FROM accommodation WHERE lat > '(base_lat - 0.2)' AND lat < '(base_lat +0.2)' AND long > '(base_lon - 0.2)' AND long < '(base_lon+0.2)'"; // // base_lon and base_lat have already been predefiend e.g $base_lon = xxx; $base_lat = xxx; Im basically trying to query my accomodation database and find all accomodation near to a base location cheers Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/ Share on other sites More sharing options...
Matthias_ Posted April 4, 2010 Share Posted April 4, 2010 $query_accommodation="SELECT * FROM accommodation WHERE lat > '($base_lat - 0.2)' AND lat < '($base_lat +0.2)' AND long > '($base_lon - 0.2)' AND long < '($base_lon+0.2)'"; That should work. Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036689 Share on other sites More sharing options...
ignace Posted April 4, 2010 Share Posted April 4, 2010 It should be: SELECT * FROM accommodation WHERE lat > (base_lat - 0.2) AND lat < (base_lat +0.2) AND long > (base_lon - 0.2) AND long < (base_lon+0.2) Enclosing it between quotes made it convert from string to integer which would result in: lat > base_lat AND lat < base_lat AND long > base_lon AND long < base_lon Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036690 Share on other sites More sharing options...
madmax3 Posted April 4, 2010 Share Posted April 4, 2010 Check this: $query_accommodation="SELECT * FROM accommodation WHERE lat > '($base_lat - 0.2)' AND lat < '($base_lat +0.2)' AND long > '($base_lon - 0.2)' AND long < '($base_lon+0.2)'"; Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036692 Share on other sites More sharing options...
fraser5002 Posted April 4, 2010 Author Share Posted April 4, 2010 Hi All thanks for the replies it seems to be a problem with the longitude part of the query as this is still not working is it because the longitudes are negative numbers? This works $query_accommodation="SELECT * FROM accommodation WHERE lat > ($hill_lat - 0.2) AND lat < ($hill_lat +0.2)") this does not work $query_accommodation="SELECT * FROM accommodation WHERE lat > ($hill_lat - 0.2) AND lat < ($hill_lat +0.2) AND long > ($hill_lon - 0.2))"; like i said the longitude values in question is negative but why should this make a difference? Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036760 Share on other sites More sharing options...
fenway Posted April 4, 2010 Share Posted April 4, 2010 Echo the ACTUAL query you're sending to the server -- and you'll see. Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036788 Share on other sites More sharing options...
fraser5002 Posted April 4, 2010 Author Share Posted April 4, 2010 i have done this $hill_lon = -5.00352 long in database = -5.1069 long field in database is stored as a float i dont really understand why this should throw the error Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1036808 Share on other sites More sharing options...
fenway Posted April 6, 2010 Share Posted April 6, 2010 Like I said... echo the full query. Link to comment https://forums.phpfreaks.com/topic/197530-what-is-wrong-with-this-sql-query/#findComment-1038041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.