function printLeveesByZip($zip) { echo "<ol>"; $query = "SELECT * FROM leveerisk"; $result = mysql_query($query); while ($levee = mysql_fetch_array($result)) { $z = new zipcode_class(); $miles = $z->get_distance($zip, $levee[zip]); //if($miles === false) echo '<p>Error: '.$z->last_error.'</p>'; if ($miles < 100) { printLeveeDetails($levee[id]); } } echo "</ol>"; }
/* DEMO for using the zipcode PHP class. By: Micah Carrick Questions? Comments? Suggestions? email@micahcarrick.com */ require_once 'zipcode.class.php'; // zip code class // Open up a connection to the database. The sql required to create the MySQL // tables and populate them with the data is in the /sql subfolder. You can // upload those sql files using phpMyAdmin or a MySQL prompt. You will have to // modify the below information to your database information. mysql_connect('localhost:3306', 'trailblazer', 'trailblazer') or die(mysql_error()); mysql_select_db('zip_codes') or die(mysql_error()); // Below is an example of how to calculate the distance between two zip codes. echo '<h3>A sample calculating the distance between 2 zip codes: 93001 and 60618</h3>'; $z = new zipcode_class(); $miles = $z->get_distance(97214, 98501); if ($miles === false) { echo 'Error: ' . $z->last_error; } else { echo "Zip code <b>97214</b> is <b>{$miles}</b> miles away from <b>98501</b>.<br />"; } // Below is an example of how to return an array with all the zip codes withing // a range of a given zip code along with how far away they are. The array's // keys are assigned to the zip code and their value is the distance from the // given zip code. echo '<h3>A sample getting all the zip codes withing a range: 2 miles from 97214</h3>'; $zips = $z->get_zips_in_range('97214', 2, _ZIPS_SORT_BY_DISTANCE_ASC, true); if ($zips === false) { echo 'Error: ' . $z->last_error; } else { foreach ($zips as $key => $value) {