Jump to content

Correct syntax for $_GET


Jellicle

Recommended Posts

Chaps

 

I'm doing some searching for locations within 2 kms of my user, using an SQL query:

 

This works with my current location hard coded (the values 150.899827 and -34.417236 are the hard coded bits):

 

$query = "SELECT *, ( 6371 * acos( cos( radians('150.899827') ) * cos( radians( lati ) ) * cos( radians( longi ) - radians('-34.417236') ) + sin( radians('150.899827') ) * sin( radians( lati ) ) ) ) AS distance FROM allcafes HAVING distance < 2 ORDER BY distance LIMIT 0 , 20;";

 

However, when I pass latitude and longitude values to the script via a URL e.g.

 

http://mydomain.com/scripts/searchbydistance.php?latitude=150.899827&longitude=-34.417236

 

I get nothing in the result. So I'm thinking that my syntax for the $_GET in my PHP file might be wrong.

 

Can someone look at the following and tell me if it looks ok?

 

  $query = "SELECT name,lati,longi, ( 6371 * acos( cos( radians('".mysql_real_escape_string($_GET['latitude'])."') ) * cos( radians( lati ) ) * cos( radians( longi ) - radians('".mysql_real_escape_string($_GET['longitude'])."') ) + sin( radians('".mysql_real_escape_string($_GET['latitude'])."') ) * sin( radians( lati ) ) ) ) AS distance FROM allcafes HAVING distance < 2 ORDER BY distance LIMIT 0 , 20";

 

With grateful thanks,

 

Jellicle

Link to comment
https://forums.phpfreaks.com/topic/256290-correct-syntax-for-_get/
Share on other sites

D'oh. Who would have thought passing the location values in the wrong order would make a difference? :)

 

I'm still shiny new at this programming lark - must remember... check the inputs when the outputs are wrong... check the inputs when the outputs are wrong.. check the inputs when the outputs are wrong..

 

Thanks!

 

Jellicle

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.