Jump to content

What is wrong with this sql query


fraser5002

Recommended Posts

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

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.