zip codes
Date: 09/07/05
(MySQL Communtiy) Keywords: php, mysql, html, database, sql
i'm doing a project where i need to measure distances between zip codes; en route to a solution i stumbled upon a couple of handy resources that i figured i'd pass along:
http://www.zend.com/codex.php?id=1486&single=1
a class used to do various zipcode calculations such as distance and finding the zip codes within range of another zip code
take a look at the class to see how he wants your tables and fields named for the state and zip code database tables
http://www.cfdynamics.com/cfdynamics/zipbase/index.cfm
zipbase - datbase of zip codes with lat & long info, state info, etc. available in a text file and an access datbase
i used the textfile and in mysql said:
mysql> LOAD DATA LOCAL INFILE 'c:/ZIP_CODES.txt'
-> INTO TABLE zip_code
-> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
-> LINES TERMINATED BY '\r\n';
http://27.org/isocountrylist/usps_states_list.sql
SQL file for creating a states table (i believe in the zipcode class, he wants the states table called "state")
i used that to make a silly little app to test some of the features of the class:
$zip){
$field = 'zip'.($key+1);
if(isset($_REQUEST[$field])){
if(is_numeric($_REQUEST[$field])){
$zips[$key] = $_REQUEST[$field];
}
}
}
?>
foreach($zips as $key => $zip){
if($zip){
echo "
";
echo "$zip:";
$details = $zc->get_zip_details($zip);
if(!empty($details)){
foreach($details as $key => $value){
echo "- $key: $value
";
}
}
echo "
";
}
}
?>
if($zips[0] && $zips[1]){
echo "Distance: ".$zc->get_distance($zips[0], $zips[1]);
}
?>
oh, and i found this http://centricle.com/tools/html-entities/ to convert app code into HTML special chars
crossposted in php mysql & bobalien
Source: http://www.livejournal.com/community/mysql/67585.html