US zip code population using PHP MySQL

297 views Asked by At

I've created a HTML ZIP code select menu. I've imported a zipcode sql file to my database. ZIP code options are populated using php and mysql select query. Everything works fine. But it's taking too long to load. There are 42741 zips in US.Is there any way to reduce its loading time?

Code is given below..

<select name="zips[]">
    <option value=""></option>
    <?php
        require("db/dbconfig.php");
        $result=mysql_query("SELECT * FROM `zipcodes`");
        while($row=mysql_fetch_assoc($result)){
    ?>
    <option value="<?php echo $row['ZIP'];?>"><?php echo $row['ZIP'];}?></option>
    <?php    
    ?>

1

There are 1 answers

2
Quentin On BEST ANSWER

Just let people type the zip code they want. It's a lot faster and easier then picking it from a list and you won't need to send a copy of the list every time the page loads.

Check the zip code against the list of acceptable ones after the data has been submitted.