pquery Posted December 26, 2007 Share Posted December 26, 2007 I just need a little help on where to look for a simple function I'd like to build into my application I'd like to put a simple mySQL db backend that holds zip codes and their corresponding cities, there has to be one of these availalbe for download somewhere right? I don't want lats or or longs just zip and corresponding cities. I'm sticking with the KISS rule (this is a free web tool and nothing is too complex on it) second where can I go to look for some help on the lookup function for this? Like I said I just want simple, you put your 5 digit zip code into the txt field and then I can have my js validator make sure that it's all numerical, and in a certain range of us zip codes, and then have the php do the look-up and return the $city,$state for the echo statement. nothing complex, I'm sure one if not many have done things like this already. But everytime I search for something it's doing area ranges based on lat/long tables or shipping tables. I'm just looking for SIMPLE. thanks Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 26, 2007 Share Posted December 26, 2007 google it, you might have to pay for the array, but its fairly striaghtforward and a good use for ajax, I know of ajax tutorial out there that uses this array, but I can't locate it. Quote Link to comment Share on other sites More sharing options...
drummer101 Posted December 26, 2007 Share Posted December 26, 2007 Most of the ones I've found out have to pay for. http://www.odditysoftware.com/page-datasales40.htm But give http://www.maxmind.com/download/worldcities/cities.txt.gz a look, it's free (clocks in @ 33mb though) I'm DLing it now to look it over but maybe it's what you're looking for? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 26, 2007 Share Posted December 26, 2007 these are the sorta resources people need to consolidate into one place for free Quote Link to comment Share on other sites More sharing options...
pquery Posted December 26, 2007 Author Share Posted December 26, 2007 I've actually found the db in Microsoft access format and I'm converting now. In case anyone else is looking I found it on about.com in the database section, and the data is from 2006. I'm still looking for the php function so that I don't have to sit here and write it from scratch (just to save some time) so if someone knows something please let me know. thanks. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Just do a simple LIKE or greater than/less than search on the zip. Quote Link to comment Share on other sites More sharing options...
drummer101 Posted December 26, 2007 Share Posted December 26, 2007 http://zips.sourceforge.net/ try that one, theres a sql format and CSV Quote Link to comment Share on other sites More sharing options...
pquery Posted December 29, 2007 Author Share Posted December 29, 2007 I just converted the MS access free db to csv and then uploaded to my local copy of mySql. Then I exported and uploaded to my server. (both the city and state abbr. were in all uppers) I then wrote a simple function to do what I need including capitalizing only the first name of the city but keeping the 2 letter state code in caps.... I'll share for others looking for something simple global $dbh; global $zipCode; $query =mysql_query("SELECT `city` , `state` FROM `zipCodes`WHERE `zip` =$zipCode"); $query_row=mysql_fetch_array($query); $city = ucfirst(strtolower($query_row[0])); echo($city); echo(","); echo($query_row[1]); mysql_close(); just remember that it's taking a form text field named zipCode if you're going to reuse this, and my zipcode table was named zipCodes. As a final note, if anyone knows of a free db full of the canadian zips I'd take a link to that to merge with my US zip codes - remember I'm only looking for zip code, city and state / providence abbr. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.