Zipcode Distance Problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gladiator2043
Forum Newbie
Posts: 2
Joined: Tue Aug 10, 2004 12:07 pm

Zipcode Distance Problem

Post by gladiator2043 »

I am developing an app that gets a zipcode from a user and then uses that zipcode to find the nearest store locations in miles based on the stores zipcode.


I have a database that has all the zipcodes with there corresponding latitudes and longitudes.
I also have a calculation that computes distance between the zipcodes.

The problem I am facing is that I need the result to be sorted by distance. The issue at hand is that distance is calculated on the fly and how do I sort something that is computed on the fly by a PHp function.

Any help will be highly appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if the distance is calculated inside the sql query, you can "order by" that. If the distance is calculated by php, then you can use usort() or it's sibling functions uasort()/uksort()

each of which uses a user defined comparison function. We talked about it's use very recently if you look through the php-code board.
Post Reply