Jump to content

[SOLVED] simple zip code lookup to city & state


pquery

Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.