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
postalcode search
Moderator: General Moderators
You be wanting to use thar webservice on http://www.geonames.org/ - it be a REST-query, yar.
- happy_tapper
- Forum Newbie
- Posts: 5
- Joined: Mon Sep 18, 2006 5:51 am
- Location: UK
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 :
Then display your results in a table.
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%' ");- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.
I also found GeoClass PHP useful.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA