So I have a php page(hence the $ variables) that given some zipcode and distance will return all zip codes within the given miles sorted by distance. I want to be able to use column "DIST"
Is there a way I can not make the query calculate this twice?
I tried to do this:
however it said it can't find the unknown column 'dist'
Any suggestions?
THANKS!
Code:
SELECT zip, latitude, longitude,
DEGREES(acos(sin('$rlat')*sin(RADIANS(latitude))+COS('$rlat')*COS(RADIANS(LATITUDE))*COS('$rlong'-(RADIANS(LONGITUDE))))) as distance
FROM zipcodes WHERE (DEGREES(acos(sin('$rlat')*sin(RADIANS(latitude))+COS('$rlat')*COS(RADIANS(LATITUDE))*COS('$rlong'-(RADIANS(LONGITUDE))))) <= '$degree') ORDER BY dist;
Is there a way I can not make the query calculate this twice?
I tried to do this:
Code:
FROM zipcodes WHERE (dist <= '$degree')
however it said it can't find the unknown column 'dist'
Any suggestions?
THANKS!