agtlewis wrote:Is it possible to order the results by distance without using this equation in the query? If not, is it possible to speed this up?
No, distance will always be calculated. It will either be calculated in the query or code-side, but it is always calculated.
The general process is to identify a zipcode, locate the lat and lon associated with that zipcode, then, using the radius, draw a circle around the lat and lon point to determine the set of points within the circle. That is fairly easy to for the database. However, from one point to another, you need to identify each lat/lon pair for each zipcode within the circle THEN run that crazy equation to calculate the distance.
I have tried to so what you are doing both ways. I have found, through many a late night and early morning headache, that the most efficient way to calculate the distance and sort by it is with your code, not the database. To do this, grab all the records in the database that fall within the circle. Use PHP to calculate the distance within the result array, then when it comes times to display the results, sort the array on the created 'distance' key. Experience (at least my experience) has shown that this is the fastest and most efficient way to run the calculations.