postalcode search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

postalcode search

Post by hame22 »

Hi,

I was wondering if there is a way/tool in PHP which can be used to do searches involving postal codes.

e.g. I have a directory of users and would like to search for users close to an entered postal code

in php is there an easy way to achieve this?

Thanks in advance
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You be wanting to use thar webservice on http://www.geonames.org/ - it be a REST-query, yar.
User avatar
happy_tapper
Forum Newbie
Posts: 5
Joined: Mon Sep 18, 2006 5:51 am
Location: UK

Post by happy_tapper »

Supposing you have a list of users and their post codes in a table, you could submit a query searching for all users where the post code is like whatever is entered.

eg

Insert code for user to input search query, then something like :

Code: Select all

$result = mysql_query ("SELECT users FROM database WHERE postalcode LIKE '%$input%' ");
Then display your results in a table.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is this for proximity searching (all users within X miles of some_zip) or for straight searching on the postal code?
Skeptical
Forum Newbie
Posts: 8
Joined: Mon Sep 18, 2006 10:23 pm

Post by Skeptical »

You will need to purchase or download a zip code database. Within the database, it will contain the exact GPS coordinates of a particular zip code. You will then be able to perform proximity searches using trig functions. It's as simple as that.

Search the net for zip code databases. Many companies sell it. I believe there are free ones as well, but they won't be up-to-date.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Once you have Lat/Long distance for postcodes you need not just Trig Functions but "Great Circle Distance" formulas. A search using google should give more information.

I also found GeoClass PHP useful.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

also... google maps has a really cool geocoder...
AJAX
Standard HTTP
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Search these forums for Zip Code. Burrito mentioned a great link a few weeks back.
Post Reply