Hi Guys,
I'm working on a function that will find a range of zip codes within a particular passed zip code.
Example
Find all zips within 50 miles of 63101
However, the form allows users to enter in City, State instead of zip.
I've got everything figured out on how to parse out the city and state, find matches in the database, and return all the zips that match for that city.
In the case of say, St. Louis, there are dozens of zip codes. So if someone searches for something within 50 miles of St. Louis, MO, my code, at this point, has a long array of zips that match.
The code I have that searches for other zips within a radius only allows one zip to be passed. If I were to pass all zips, I'd essentially have to loop through each zip, find all zips within a range of each zip in the loop, combine the results, sort out duplicates, etc. etc. This would be very inefficient.
So I'm thinking of the best way to just grab one zip out of the city's array of matching zips and use that in the search.
Ideas.
1. List the array out, and the grab one from the middle. Say the city has 19 zips, grab like the 9th one in the list (sorted numerically) and just use that.
2. Use the first zip in the array, sorted numerically.
3. Use the last zip in the array, sorted numerically.
Thoughts?
I'm working on a function that will find a range of zip codes within a particular passed zip code.
Example
Find all zips within 50 miles of 63101
However, the form allows users to enter in City, State instead of zip.
I've got everything figured out on how to parse out the city and state, find matches in the database, and return all the zips that match for that city.
In the case of say, St. Louis, there are dozens of zip codes. So if someone searches for something within 50 miles of St. Louis, MO, my code, at this point, has a long array of zips that match.
The code I have that searches for other zips within a radius only allows one zip to be passed. If I were to pass all zips, I'd essentially have to loop through each zip, find all zips within a range of each zip in the loop, combine the results, sort out duplicates, etc. etc. This would be very inefficient.
So I'm thinking of the best way to just grab one zip out of the city's array of matching zips and use that in the search.
Ideas.
1. List the array out, and the grab one from the middle. Say the city has 19 zips, grab like the 9th one in the list (sorted numerically) and just use that.
2. Use the first zip in the array, sorted numerically.
3. Use the last zip in the array, sorted numerically.
Thoughts?