Jellicle Posted February 3, 2012 Share Posted February 3, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256290-correct-syntax-for-_get/ Share on other sites More sharing options...
Pikachu2000 Posted February 3, 2012 Share Posted February 3, 2012 Have you echoed the query string to make sure the values are correct? Quote Link to comment https://forums.phpfreaks.com/topic/256290-correct-syntax-for-_get/#findComment-1313905 Share on other sites More sharing options...
Jellicle Posted February 3, 2012 Author Share Posted February 3, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256290-correct-syntax-for-_get/#findComment-1313946 Share on other sites More sharing options...
glennn.php Posted February 3, 2012 Share Posted February 3, 2012 isn't it frustrating that humans are still wrong oftener than the computer is...??? Quote Link to comment https://forums.phpfreaks.com/topic/256290-correct-syntax-for-_get/#findComment-1314045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.