PHP Zip Code Range and Distance Calculation
April 19th, 2005
This is a PHP class to do various calculations with zip codes. It's primary purposes are to calculate the distance between two zip codes and to extract all the zip codes that are within a range of a given zip code. All calculations are based on lattitude and longitude coordinates stored in the database. Included is a class file, demonstration file, and the sql files required to create and populate the MySQL tables.
Download:
zipcode-1.2.0.zip
Do you like this code? Rate This Script at Hot Scripts.
Here is a Postgresql port of the zip code database to contributed by max: zip_codes_postgresql.zip.
Version History
- v1.2.0 [Oct 22, 2006] - Using a completely new database based on user contributions which resolves many data bugs. Added sorting to get_zips_in_range(), added ability to include/exclude the base zip from get_zips_in_range()
- v1.1.0 [Apr 30, 2005] - Added Jeff Bearer's code to make it MUCH faster!
- v1.0.1 [Apr 22, 2005] - Fixed a typo :)
- v1.0.0 [Apr 12, 2005] - Initial Version
Setting up the Database
There are 6 files in the /sql directory which contain SQL statements intended for a MySQL database (though they should work just fine for any SQL database). The zip code database consists of over 40,000 records which would be too large a file for many configurations of phpMyAdmin. Therefore, I have broken the data into records of 10,000 resulting in 5 files. In phpMyAdmin, you can import these 6 files 1 at a time using the 'Import' tab. You MUST import the 'create_table.sql' file first, then each of the data files.
create_table.sql
data_1.sql
data_2.sql
data_3.sql
data_4.sql
data_5.sql
The database has changed since the last version. The data itself is comprised of data from multiple sources starting with the 2000 and 2004 US Census data. Unlike version 1.x of this class, the database is no longer comprised of a state AND zip_code table, but a single zip_code table. Additionally, the table is created with an index on the zip_code column.
The Class: zipcode.class.php
Constants
// constants for setting the $units data member
define('_UNIT_MILES', 'm');
define('_UNIT_KILOMETERS', 'k');
// constants for passing $sort to get_zips_in_range()
define('_ZIPS_SORT_BY_DISTANCE_ASC', 1);
define('_ZIPS_SORT_BY_DISTANCE_DESC', 2);
define('_ZIPS_SORT_BY_ZIP_ASC', 3);
define('_ZIPS_SORT_BY_ZIP_DESC', 4);
// constant for miles to kilometers conversion
define('_M2KM_FACTOR', 1.609344);
Data Members
| decimals | Read/Write. When returning distance values, this variable determines how many decimal places the result should be rounded to. |
| last_error | Read-only. Holds a string value of the last error that occured. This can be used should a method return an error value to get a human readable version of the error. |
| last_time | Read-only. Holds the last method execution time used to debug the efficiency of the get_zips_in_range() method. |
| units | Read/Write. Holds the type of units to show results in. Must be either _UNITS_MILES or _UNITS_KILOMETERS |
Methods
| calculate_mileage($lat1, $lat2, $lon1, $lon2) | Calculates the mileage between the two lattitude/longitude points: $lat1/$lon1 and $lat2/$lon2. |
| chronometer() | Chronometer function from PHP manual used to time execution of get_distance() and get_zips_in_range() methods. |
| get_distance($zip1, $zip2) | Returns the distance between the two zip codes: $zip1 and $zip2. If there is an error, false is returned. Since the function can return 0 when 2 zips are the same, you must evaluate for an error condition using: if (get_distance($zip1, $zip2) === false) // error condition |
| get_zip_details($zip) | Returns the details about the zip code: $zip. Details are in the form of a keyed array. The keys are: latitude, longitude, city, county, state_prefix, state_name, area_code, and time_zone. All are pretty self-explanitory. Returns false on error. |
| get_zip_point($zip) | Gets the lattitude and longitude coordinates of the given zip code as a keyed array. The keys are: lat and lon. Returns false on error. |
| get_zips_in_range($zip, $range, $sort,$include_base) | Finds all zip codes within $range from $zip as a keyed array sorted by $sort. If $include_base is set to true or not specified, then $zip is included in the results. If it is set to false, then $zip is excluded from results. Possible values for $sort are: _ZIPS_SORT_BY_DISTANCE_ASC (default), _ZIPS_SORT_BY_DISTANCE_DESC, _ZIPS_SORT_BY_ZIP_ASC, _ZIPS_SORT_BY_ZIP_DESC. The return value is a keyed array where the key is the zip code and the value is the distance from the base zip $zip. Returns false on error. |
Categories
Popular Posts
RSS Feeds
Archives
September 26th, 2007 at 10:43 pm
Does this script still exist? How can one obtain it? The zip file db-1.0.4.zip seems to contain something else
September 27th, 2007 at 9:16 am
I apologize. I have fixed the link. You can now download the zip code class.
September 27th, 2007 at 11:40 pm
thanks for the great app Micah... It was a huge time saver!
September 28th, 2007 at 9:05 am
Sure thing. I'm glad you liked it.
October 11th, 2007 at 11:37 am
Hi,
Is there anything special that needs to be done to the script to make it work for English postcodes?
The format of a typical english postcode is either AB10 1XL or AB1 1XL.
Great script BTW... if I can get it working for England it will ahve saved me a HUGE amount of time ;)
Matt
October 11th, 2007 at 8:43 pm
Great script! I'm trying to loop through results passed by a URL variable
i tried working with the get_zips_in_range.....
get_zips_in_range(''.$_GET['zip'].'', $_GET['miles'], _ZIPS_SORT_BY_DISTANCE_ASC, true);
{
foreach ($zips as $key => $value) {
echo "$key is $value miles away.";
}
}
?>
And
get_zip_details('$zips');
if ($details === false) echo 'Error: '.$z->last_error;
else {
foreach ($details as $key => $value) {
$key = str_replace('_',' ',$key);
$key = ucwords($key);
echo "$key: $value";
}
}
?>
and ideas (basically trying to do a store locator off of your script
October 12th, 2007 at 10:47 am
Matt: the script uses a database populated with US zip codes. For UK postal codes, you would need to obtain data including at least the postal code, latitude, and longitude. I'm not sure if any such database exists for free.
October 12th, 2007 at 10:48 am
Jonathan: I don't have time to get into the details now, but when I have time I'll try to dig up an example of using the script as a store locator.
October 12th, 2007 at 11:23 am
Hi,
Sorry, I should have said that already have a database full of UK postcodes along with latitudes and longitudes. In fact with no changes your class calculates the distance between postcodes fine... however it errors when trying to find those codes within a radius.
In order to get it to work as far as i have, i simply took your demo.php file and changed the static zip_codes for postcodes in my DB. So literally with only changing those i have the first part working, i just can't see why the codes within a range isn't. All it comes up with is "Error:" but no actual error message.
Any help you could give would be most appreciated. My first thoughts were that you might be performing some kind of validation on the zip_codes, in which case postcodes would fail... but as the distance between codes works i can't see how this would be the case. Below is an entry from my DB:
postcode x y lattitude longitude
AB10 392900 804900 57.135 -2.117
I have obviously changed the SQL to match my tables. The X and Y values aren't used at all... they just came with the data.
Thanks for your help
October 12th, 2007 at 11:49 am
Make sure the SQL in get_zip_point() as well as get_zips_in_range() matches your table column names. Also make sure that the order of the column names in the SQL are the same as my original ones since I'm using the array indexes and not their keys.
Looking at it very quickly, I think maybe 0 rows are returned? Try changing the get_zip_point() method from this:
if (!$r) {
$this->last_error = mysql_error();
return false;
} else {
$row = mysql_fetch_array($r);
mysql_free_result($r);
return $row;
}
to this:
if (!$r) {
$this->last_error = mysql_error();
return false;
} elseif (!$row) {
$this->last_error = "Zip code $zip was not found in the database.";
return false;
} else {
$row = mysql_fetch_array($r);
mysql_free_result($r);
return $row;
}
October 12th, 2007 at 3:55 pm
Oh dear... time for me to put on the idiot hat I think!
Thank you for your help... you were right about one thing... 0 rows were being returned... but not because of any problems with SQL or coding... there were simply none in a 2 mile range!
If you add the following to the code in get_zips_in_range then it will let you know there were 0 in range:
if (!$r) { // sql error
$this->last_error = mysql_error();
return false;
} elseif (mysql_num_rows($r)==0) {
$this->last_error = "There were 0 zips within range";
} else {
Thanks for all your help... and i'll say it again, great script!
October 12th, 2007 at 4:06 pm
Right. I noticed that as well. I'm going to make that little change and re-upload the file.
October 15th, 2007 at 10:50 am
Micha - Awesome script! Just real quick, I'm going to point you to a post I made on a php developer forum. I was able to turn your script into a dealer locater type thing where it fetches records from a db table based on the zipcodes it found within X miles from a zipcode you enter. The only remaining issue I have is sorting the output by miles. I know your script does this by default but I took it a step further and grabbed information from a mysql table.
If you can just briefly look at the code (it's not long) and give me some advice, I would appreciate it. I am not asking you to rewrite it for me, just some tips or advice so i can figure out where to go from here.
http://forums.devshed.com/php-development-5/need-to-sort-output-by-distance-481694.html
October 18th, 2007 at 9:20 am
Wow, this looks great. I'm going to try it out and if it works I'll be back to give you a donation. It looked like I might have to pay $50 for this solution elsewhere. Nice that others also contributed some performance boosters (based on your versions). I'm psyched!
October 22nd, 2007 at 7:51 am
Hi!
Could anyone please suggest me how to set up a similar database for Italian ZIP (CAP) codes?
Thank you!
Bye bye
Davide
October 22nd, 2007 at 9:02 am
I don't know of any free databases other than the US one. Often times the data is available (though perhaps as text file or other obscure method) through a government agency website.
October 30th, 2007 at 9:56 am
I see people asking about non-US databases, but is there a free up to date US zip code database that can downloaded somewhere?
October 30th, 2007 at 10:06 am
The download includes a free US database. However, it might not be entirely up to date--though I am using it on a commercial site with no problems to date. Whenever a change is found/needed and I am notified, I add it to the database.
November 2nd, 2007 at 7:18 am
Rather than downloand and install, I'd like to run a query for zips 40 miles in radius from 21030 and have a list of zips returned. If anyone has this script online on an accessible webserver, can you please post a URL? Sounds like a wonderful scrip!
Thanks,
Rich
November 3rd, 2007 at 9:33 am
Is there an update to the zip code database available?
November 3rd, 2007 at 10:32 am
The database included in the zip is the most recent one I have.
November 21st, 2007 at 11:23 pm
how can i creat the form that will work with this data base !
November 24th, 2007 at 9:00 pm
incredible...that's about all i can say. you have saved me TONS of time. I've gotta be honest, I usually don't leave comments but im just blown away by the script and had to say something. thanks a lot
November 25th, 2007 at 6:35 pm
This is an excellent script. I ended up adapting it as a "Find A Club" script for District 39 Toastmasters since the core of the code is finding all matches by latitude/longitude (See www.district39.org/findclub , although the lookup is restricted to Northern California/Western Nevada clubs). I did change the lat/lon datatypes from FLOAT to DOUBLE for accuracy.
As for sources of free zip codes that are up to date, see http://geocoder.ibegin.com/downloads.php . You may need to apply PHP string fuctions so that it isn't all caps. Not aware of a source for Canada ZIP codes that are FREE.
November 29th, 2007 at 11:42 pm
Mark or Micah, would you be so kind as to share how you modded the script for the club search?! That would be amazing!
November 30th, 2007 at 4:26 pm
This is an interesting little snippet but I think you could improve it if you get rid of the database requirement and add a mashup option. You could look at my store locator for an example of how that type of implementation would go. I once had a requirement of using a zipcode DB also but I soon found that people were complaining of zip data being out of date. So rather than updating the zips DB every few months, I decided to let someone else do that and used some geocoders instead (Yahoo and Google Maps for example). Something like this would have been nice when I first started coding my locator.
December 1st, 2007 at 4:05 pm
Hi,
Can some one please show me how I can include this in a simple form to calculat distance between two zip codes, thanks.
Moody
December 3rd, 2007 at 2:06 pm
i think u use the method "get_zips_in_range($zip,$range,$sort, $include_base)" shown above...
i too am trying to get the closest location from the var $zip from the input of the form...
i guess u need to input range as well, or predefine somehow
hoep this helps i am noob lol 8^p
December 3rd, 2007 at 3:26 pm
it is used in the demo.php file u get with the class.....
$zips=$z->get_zips_in_range($zip, $range, $sort, $include_base) where $zip is a var from your
html form
so your form should look something like this:
December 6th, 2007 at 2:57 pm
Zip1
above is my form code, when i hit submit it should pass zip1 to the method below
echo 'A sample getting all the zip codes withing a range: 2 miles from '.$_POST['zip1'].'';
$zips = $z->get_zips_in_range('zip1', 2, _ZIPS_SORT_BY_DISTANCE_ASC, true);
if ($zips === false) echo 'Error: '.$z->last_error;
else {
foreach ($zips as $key => $value) {
echo "Zip code $key is $value miles away from ".$_POST['zip1']".";
}
is this correct?
cheers
nate
December 28th, 2007 at 2:49 am
I have been running this script for some time now. Its one of the best I have found out there. Thanks for maintaining this Micah.
January 14th, 2008 at 6:58 pm
Can your script work with social engine?
http://www.socialengine.net
January 21st, 2008 at 9:27 pm
Hi Micah,
This is some awesome code and I've found it really useful for a project I've been working on recently. However, I found a bug in the get_zips_in_range function that's going to throw off the accuracy of the results. Your code uses:
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($details[0]) * 69.172));
I was doing the math to make sure things seemed fine, as I wanted to wrap my head around the calculations. Everything seemed fine until I hit the cosine in the $lon_range calculation - PHP's cos() function expects a value in radians, but it's receiving a value in degrees. The other functions use the deg2rad() function to correct this, but not here. I just wanted to let you know since it can produce results that include either a pretty accurate longitude range or something wildly inaccurate due to the cyclical nature of cosine. Just wrap $details[0] in deg2rad() and the problem goes away, as far as I can tell.
I confirmed things with this snippet:
$range = 5;
echo 'With deg2rad: ';
for ($lat = -89; $lat ";
}
echo 'Without deg2rad:';
for ($lat = -89; $lat ";
}
You can see that without the deg2rad function, the longitude range doesn't change if you increase the latitude by 2pi degrees, which is of course a full wave of cosine in radians. Switch the 2*M_PI to 5 or something just to show how it bounces all over the place w/out deg2rad but goes from narrow to wide to narrow ranges with.
I know I wouldn't have gotten where I had without finding your code, so thanks a ton for offering it up. I'd feel bad not giving back a bit, and expect a donation once the site is up and running :)
Regards,
Eric
January 21st, 2008 at 9:29 pm
Whoops, looks like wordpress parsed out half my code. Shoot me an email for the correct version.
January 24th, 2008 at 5:46 am
Lovely work and a very usefull class ... converted to my own database and used for UK postcode database ... Cheers
January 30th, 2008 at 5:59 am
In the problem Matt was having with the 0 rows, the elseif in get_zip_point() should be:
} elseif (mysql_num_rows($r)==0) {
not:
} elseif (!$row) {
Because $row can't be set until the else section, so it's always going to fail in the elseif check.
Also, similarly to sam sen's problem, I still haven't figured out an efficient way to search for the zips in the master zip_code table (to get lat/long and zips in range), then marry that data with a store location table's zip codes -- and still sort by the mileage. I can build an SQL statement on the fly with the initial returned range like "select * from stores where zip IN ('12345', '12321', '12333', '12367')", then display the result and miles with something like:
while ($row = mysql_fetch_array($stores_query))
{
echo $row[store_name] .' - '. echo $zips[$row['store_zip']] .' miles away';
}
Adding an "order by" won't really help because if someone searches for '12317', but '12314' and '12315' are in range, ordering by zip will display the other zips before the one the user actually searched for.
It probably would work with a subselect (customizing queries in the class file) but I'm NOT working with mysql 4.1 -- so I can't test this. Anyone that has a solution, please post. I'd appreciate some ideas.
February 10th, 2008 at 11:57 am
Mica
Great script - thank you.
Now the big question for me is how to reverse the search.
Let me explain - what I want is to get a list of people who are within their own specified travelling distance of an event when posted.
So for example you have a persons postcode, lat and long, and the distance they are prepared to travel in miles.
This therefore works like a radial search but in reverse s you need to go through every person in the list and effectively do a radial search based on them being in the center and seeing if the event is within the search radius.
This is ok with only a small Db but i am guessing it gets longwinded for a large one.
Sorry I haven’t posted code but I’m a noob so anything i post is likely to be a red-herring.
I am however keen on making this work so glad of any pointers or assistance you or others can give.
Many thanks
GreenBoy
February 12th, 2008 at 3:43 pm
Hi - Great Work!!
I've converted the SQL so that it works for PostgreSQL, Drop me a line if you want me to ZIP the SQL files and email them to you.
Max
February 13th, 2008 at 6:00 pm
Hey Micah. Great work.
I've integrated your code into my site.. http://www.SpeedyWord.com/
February 20th, 2008 at 9:33 pm
hello I'm new to php, I'm trying to make a function that will allow users to calculate distance between two zip codes and based on the miles give a dollar value. I have the database ready I just need to get this form to work. Thank you for you Time.
February 21st, 2008 at 3:08 pm
Hey Micah, this is great work.
Btw, Google has posted a tutorial on how to create a store finder using their map API...maybe this helps someone here: http://code.google.com/support/bin/answer.py?answer=87134&topic=&ctx=sibling
-Mark
March 2nd, 2008 at 2:58 pm
So, how did I adapt it as a club finder....
As the routine is designed, the results from a MySQL query is returned as Zip Code, Latitude, and Longitude. If you geocode every address in the club database with a latitude and longitude, you simply point the routine to search the club table rather than the zip code table and return the club numbers based upon the latitude/longitude results. The initial geocoding can be done through Google Maps API.
So, for find-a-club, the programming steps are:
1. Get the address and range of seach (I limit mine to 99 miles).
2. Parse the address through Google Maps to return the latitude and longitude.
3. Plug in the latitude and longitude into a modified version if Micah's routine to retrieve the club numbers and mileage.
4. Take the club numbers and pull up the results.
Thanks, Micah!
March 16th, 2008 at 8:45 pm
I have integrated this script into an open source script I am developing called Open Auto Classifieds http://openautoclassifieds.com and this is a very helpful script and just wanted to say thank you!
March 18th, 2008 at 1:31 pm
I m getting error when am find the range of zip code 96006. can any one help me out that why i m faceing this error ? n how can i slove it
March 27th, 2008 at 10:46 am
Excellent script! Like others here, I hope to use it to build a proximity search application. I'm wondering though, if its possible to call the get_zip_details function within a for loop that uses get_zips_in_range? And if so, what would the syntax to do that?
I tried using a for loop within a for loop to no avail.
If I am able to do this, then the proximity search and details about each are accomplished all in one shot.
I am, of course, planning on modifying the script to suit my needs, but if I could figure a way to pull the details of each while going through the proximity search, that would be great!
March 27th, 2008 at 3:59 pm
Trying to set up a distance calculator where a person selects a location and then enters their zip code and the distance calculator spits out the distance. I'm stuck. uploaded is what i believe is needed for the basic premise to work, but it isn't. sos. mayday. HELLLLLLLP.
Zip Code Range and Distance Calculation Demo
BODY, P { font-family: sans-serif; font-size: 9pt; }
H3 { font-family: sans-serif; font-size: 14pt; }
Sacramento, CA
Colorado Springs, CO
Denver, CO
Berlin, CT
Jacksonville, FL
Orlando, FL
Atlanta, GA
Boise, ID
Central Chicago, IL
Chicago, IL
Elgin, IL
Woodridge, IL
Indianapolis, IN
Merrillville, IN
Baltimore, MD
Frederick, MD
Washington DC, MD
Detroit, MI
Grand Rapids, MI
Southgate, MI
Westland, MI
Minneapolis, MN
Springfield, MO
St. Louis, MO
Albany, NY
Buffalo, NY
Long Island, NY
Niagara Falls, NY
Syracuse, NY
Charlotte, NC
Greensboro, NC
Akron, OH
Canton, OH
Cincinnati, OH
Columbus, OH
E. Cleveland, OH
Mentor, OH
W. Cleveland, OH
Portland, OR
Philadelphia, PA
Pittsburgh, PA
Greer, SC
Rapid City, SD
Knoxville, TN
Nashville, TN
Arlington, TX
Ogden, UT
Provo, UT
Salt Lake City, UT
Newport News, VA
N. Virginia, VA
Seattle, WA
Spokane, WA
Milwaukee, WI
Enter your zip code
function calculate() {
$z = new zipcode_class;
$miles = $z->get_distance($value, &zip);
}
{
if ($miles === false) echo 'Error: '.$z->last_error;
else echo "Zip code value is $miles miles away from &zip.";
}
March 28th, 2008 at 6:35 am
Where can I get the most recent ZIP data? It's not really obvious where to get it on the USPS site - and search doesn't help.
Also, does anyone have any suggestions about making this compatible with Mexican Postal codes? I'd like someone to be able to do a search for a Texas ZIP, that would also return results from Mexican postal codes (which follow the same 5 digit convention as US ZIP codes)
March 29th, 2008 at 4:15 pm
This is great script!
Thanks to Chad (2 posts before mine) i was getting an error before i added:
$z = new zipcode_class;
That fixed everything!
March 31st, 2008 at 2:52 pm
Thank you for this excellent Class. I will be trying to update the data with the 2006 data set that I have found on the web. I will post a mysql dump (haha!) for everyone there. Please check back soon.
April 1st, 2008 at 9:19 pm
After dozens of tests, maybe i have not implemented this correctly in my application, but sometimes it works, and sometimes it does not. That's the best way to describe it. It actually works sometimes, and not others. I do have my own dedicated server, so i don't think it's a server problem.
Not sure where to go from here.
April 2nd, 2008 at 4:08 pm
I have the "up to today" zip code date for the US and Canada. When i say up to date.....it even has the correct cords for all the new zips and zip code moves that was done late last year.....all up to dat lat and long.
Here is the trade....I have a real large database....30 million records...and i want to split it into 999 exact databases, based on the first 3 digits of the zip code. Now i can split servers, backups alot easier with smaler databases.
Seems that the easiest way would be a fast zip code module, that calculates, and searches multiple databases based on the result. By using 3 digits, it really would only search 2 or 3.
Just for the record....we own these files....they were not scarfed somewhere. We bought 20 databases, and did a compare, then a manual lookup.
I really need the help with this.
April 6th, 2008 at 7:26 am
FYI, i have it implemented just fine now.
Thanks again for the great script.
April 9th, 2008 at 1:04 pm
Not sure if anyone caught this yet, but when calling a function that passes zipcodes, the zips should be enclosed in single quotes. This will enable lookups of zips that start or end with zeros. Without the quotes, I got a weird error telling me it couldn't find info for a zip string that I had not entered. Great script nonetheless!
April 13th, 2008 at 9:58 pm
Could u apply this to an auto search script for me and teach me how you did it by me viewing the files with you over the phone or using a confence program ? If so what would u charge me for that? and when could we get started if yes? how long do u think it would take to show me. I want to be able to know how this worked when applied to listings in database when using search form n such, thanks Lj
April 29th, 2008 at 9:15 am
One other thing I was thinking about was adding an XML page write function to the zips in range. The math portion of this is terrible on high volume servers and once its done once storing an XML of the data from the db to just pull the hardfile xml would be much much faster. Loading data into a memory table for page work is uber fast compared to redoing the math.
April 29th, 2008 at 9:34 am
function get_zip_point($zip) {
// This function pulls just the lattitude and longitude from the
// database for a given zip code.
$sql = "SELECT lat, lon from city_location WHERE zip_code ='$zip' limit 1";
Added the Limit 1 to this sql statement this prevents mysql from continue to search for more like it when we only needed one set of lat and lon from the db for another function.
Slight speed increase.
April 29th, 2008 at 11:26 am
Just found this cause I was having so much trouble with the range finding function.
Mysql will do this type of search for you directly.
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM city_location HAVING distance
April 30th, 2008 at 9:22 am
anyone help get this thing working, its like the last piece of a puzzle to get the locator operational.
Here is the complete code:
require_once('zipcode.class.php');("phpsqlsearch_dbinfo.php");
require_once('zipcode.class.php');("zipcode.class.php");
$outstanding = echo "$zip1 is $miles miles from $zip2";
function calculate() {
$z = new zipcode_class;
$miles = $z->get_distance($zip1, $zip2);
}
{
if ($miles === false) echo 'Error: '.$z->last_error;
else $outstanding
}
Your Zipcode:
Supply Zipcode:
May 5th, 2008 at 6:35 pm
Chad with the code i posted right above yours. Drop this database and geo encode your informatin and use the sql query. its lightning fast and eliminates the need for all these scripts. Not that this wasn't brilliant at the time but there is just a better way.
May 15th, 2008 at 12:46 pm
Donny,
Could you explain your sql query and what exactly it replaces and/or how to use it? Does it do the range calculation, the distance calculation or both? What are the constants 3959, 37 and -122?
May 16th, 2008 at 7:26 pm
If you add this code to your database schema SQL, it will be faster:
create index lat_idx on zip_code(lat);
create index lon_idx on zip_code(lon);
May 21st, 2008 at 9:03 am
Micah,
This script is excellent and wanted to let you know how much I appreciate your efforts. One day when I am capable of writing sound classes I hope to give back to the coding community as well - pay it forward!
June 2nd, 2008 at 12:27 am
hai great script thanks a lot
June 13th, 2008 at 3:05 am
Hi Greate script it reduced my headache very much because I had got very irritated due to this functionality
Thanks once again
June 22nd, 2008 at 3:13 pm
I haven't tried the script yet but I found interesting stuff for canadians : http://www.populardata.com/downloads.html
July 1st, 2008 at 3:00 pm
Hi Micah, great job.
I need to know if there is a newer database, how often I need to update and from where can I obtain such update.
Thanks in advance.