SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Zip code table?

  1. #1
    SitePoint Enthusiast daliren's Avatar
    Join Date
    Oct 2001
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zip code table?

    I'm working on an "online directory" project and I would like to have a table of Zip codes so that each Zip is stored only once. My problem is that my directory covers all of Northern California, which has Zipcodes from 94000-95999. Is there a way to create my ZipCode table so that each ZipCode in that range is listed automatically without me having to enter 2,000 ZipCodes by hand?

    ID Zip
    1 NULL
    2 94000
    3 94001
    4 94002
    ....................
    2000 95999
    cheers,

    Darren Cassidy

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, not automatically in MySQL. can you use PHP? if so, just use a for loop.

    PHP Code:
    for ($i 94000$i 96000$i++) { $zip_codes[] = $i; }

    mysql_query('INSERT INTO zip_codes (zip) VALUES(' implode('),('$zip_codes) . ')'); 
    done!
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Enthusiast daliren's Avatar
    Join Date
    Oct 2001
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    30 sec error

    Hi Doc;

    I tried your code by inserting it into a "connect.php" page I made and opening it in Netscape.

    After the hard drive made lots of noise for a while, I got this message in my browser:

    FATAL ERROR: Maximum execution time of 30 seconds exceeded in
    ~/connect.php on line 23 (the line with the for loop)

    I've scanned for typos and found none, what did I do wrong?
    cheers,

    Darren Cassidy

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    theres nothing wrong with the code.
    in your php.ini theres a setting for this.
    if it's exceeded, the script will fail.
    try breaking it up and doing a couple hundred at a time.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, your MySQL must be a little slow if it took longer than 30 secs. try changing the query to INSERT DELAYED INTO ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •