I’m just looking for suggestions on the best way to do this…
I need to create a search function that searches for “users” within a 50 mile radius of a zip code. I have a zip code table that contains all the U.S. zip codes with their latitude/longitude but I’m just trying to figure out the best way to structure and query my data…
Should I add latitude/longitude columns to the users table and query it for all the users within the radius of the given zip code? Or should I query the zip codes table for all the zip codes that fall within the radius then query the users table for all the users with the results(zip codes)? Or… ??? I am open to any suggestions at this point!
Thanks!
Here is the best way I have found. Of course it will require that you have all of your zipcodes lat/lon encoded in the database.
You should be able to just drop in this function. Pass it the $lat and $lon of the zipcode you want the radius for, include the optional radius, and get a list of zipcodes back.
You could very easily modify this to get all users where zipcode IN (radius_sql) and get your list users back.
Happy Coding!