Forum Moderators: coopster
"select physicians.*, round(haversine_distance(latitude, longitude, $latitude, $longitude),2) as dist from physicians, zipcode where substring(physicians.zip,1,5) = zipcode.zip order by dist, lastname"
Basically, we have two tables. One with physicians and their addresses, and one with zipcodes and their corresponding lat/long. The user enters a zipcode in a form, then a query determines the lat/long for that zipcode from the zipcode table, and then uses the resulting lat/long pair with the query above to display all the physicians in that zipcode in order of distance. Actually, what we'd like it to do is show all the nearest physicians say in a 10 mile radius, rather than just those for the zipcode entered.
Any suggestions would be appreciated. I've done some hunting for alternative haversine queries, but none seem to be returning the right results. Thanks alot!
-Matt
"select physicians.*, round(3958*3.1415926*sqrt((latitude-'$latitude')*(latitude-'$latitude') + cos(latitude/57.29578)*cos('$latitude'/57.29578)*(longitude-'$longitude')*(longitude-'$longitude'))/180) as dist from physicians, zipcode where substring(physicians.zip,1,5) = zipcode.zip order by dist, lastname"
Thanks!
-Matt