Jump to content

Sorting by Zip code


pocobueno1388

Recommended Posts

I have a table that stores the users zip code and I'm trying to display users by distance (nearest to furthest). I'm hoping there is a simple way to where I don't have to get a database with lat/long values...but when I think about it I doubt there is a formula that can measure the distance between two zip codes.

 

I would appreciate if someone could point me in the right direction. If I do need to get a database with lat/long values, it would be great if you could refer me to a good one.

 

Thanks!

 

 

 

 

Link to comment
Share on other sites

Ok, so I figured out that I would need a database full of zip codes along with their latitude/longitude. I now have that,  but I still need to figure out how to setup the query to sort users by distance.

 

Here is the relevant table information tables:

 

TABLE users
zip

TABLE zipcodes
zipcode
latitude
longitude

 

So if a user is logged in, I want it to display the users nearest to THEIR zipcode. How would I setup this query??

 

Thanks!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.