Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.