wemustdesign Posted July 22, 2011 Share Posted July 22, 2011 Hi, I am using this query to list the closest distances to a certain lat/ lon $qry = "SELECT *,(((acos(sin(($lat*pi()/180)) * sin((`lat`*pi()/180))+cos(($lat*pi()/180)) * cos((`lat`*pi()/180)) * cos((($lon- `lon`)*pi()/180))))*180/pi())*60*1.1515) AS distance FROM `location` WHERE distance <= 10"; I am getting an error: Unknown column 'distance' in 'where clause' Can anybody see what the error is? Quote Link to comment https://forums.phpfreaks.com/topic/242638-distance-query/ Share on other sites More sharing options...
premiso Posted July 22, 2011 Share Posted July 22, 2011 Sounds like you have an unknown column called distance inside of your where clause. So either your table columns are mis-named or you wrote the wrong column name in your where clause. Quote Link to comment https://forums.phpfreaks.com/topic/242638-distance-query/#findComment-1246180 Share on other sites More sharing options...
wemustdesign Posted July 22, 2011 Author Share Posted July 22, 2011 I know I do not have a distance column, I am using the calculation as distance AS distance FROM `location` WHERE distance < Quote Link to comment https://forums.phpfreaks.com/topic/242638-distance-query/#findComment-1246181 Share on other sites More sharing options...
wemustdesign Posted July 22, 2011 Author Share Posted July 22, 2011 Solved: Changed WHERE to HAVING Quote Link to comment https://forums.phpfreaks.com/topic/242638-distance-query/#findComment-1246185 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.