smith.james0 Posted January 10, 2013 Share Posted January 10, 2013 I am having a problem with the following code it should return results within 100 in distance order, but it's returning results within 100 miles but not in distance order. $code2_lat 53.447088 $code2_long -2.541988 $sqlz = "SELECT *, ((ACOS(SIN($code2_lat * PI() / 180) * SIN(lat * PI() / 180) + COS($code2_lat * PI() / 180) * COS(lat * PI() / 180) * COS(($code2_long - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `table` HAVING `distance`<='100' ORDER BY 'distance' ASC"; example of lat and long from the table 1) 53.294122 -0.340749 2) 53.347162 -2.609342 the query is returning 1 before 2 when it should be the other way round Can anyone see whats wrong? James Quote Link to comment https://forums.phpfreaks.com/topic/272939-query-problem/ Share on other sites More sharing options...
Muddy_Funster Posted January 10, 2013 Share Posted January 10, 2013 change ASC to DESC? Quote Link to comment https://forums.phpfreaks.com/topic/272939-query-problem/#findComment-1404632 Share on other sites More sharing options...
smith.james0 Posted January 10, 2013 Author Share Posted January 10, 2013 (edited) Tried that and it doesn't change anything, it's still sorting in the order they are in the table James Edited January 10, 2013 by smith.james0 Quote Link to comment https://forums.phpfreaks.com/topic/272939-query-problem/#findComment-1404639 Share on other sites More sharing options...
smith.james0 Posted January 10, 2013 Author Share Posted January 10, 2013 found the problem changed 'distance' to `distance` and it works james Quote Link to comment https://forums.phpfreaks.com/topic/272939-query-problem/#findComment-1404642 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.