Hello Forum:

I am trying to write a php script that will take as input a zip code and output the zip code with its respective city and state with the name of any companies/businesses in that zip code. Ok, I got this part working. The other part is that if the user enters a zip code that either does not exist or there is no businesses in that zip code, then the output would be a range of zip codes within, let us say, 5 miles from the zip code the user entered. I have a database with all the zip codes, latitude, longitude, city, and state columns.

Is there anyone who can help me code this in php? Thanks.
--Willie

## All 4 Replies

Wasn't this topic discussed about 5 weeks ago on this forum? Have a search. The solution, if I recall used maths (trig) functions.

Wasn't this topic discussed about 5 weeks ago on this forum? Have a search. The solution, if I recall used maths (trig) functions.

I did search before posting, but I did not find a solution. I will post my solution when I find it.

Thanks for the suggestion.

There are plenty of references on calculating the distance between two coordinates, but since you're only interested in an approximate 5 mile radius, you could just use the Pythagorean theorem and assume the curvature is negligible `dist = sqrt( (x2-x1)^2 + (y2-y1)^2 )` edit: You might find this post helpful: http://www.daniweb.com/forums/thread151916.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.