} // fldIntendedMajor $fldIntendedMajor = 'NULL'; if (!empty($_POST['fldIntendedMajor'])) { $fldIntendedMajor = "'" . mysql_real_escape_string($_POST['fldIntendedMajor']) . "'"; } // fldSelectedSchool, fldHighSchoolIds $fldSelectedSchool = 'NULL'; $fldHighSchoolIds = 'NULL'; if ($_POST['fldSchool'] != 0) { $fldSelectedSchool = "'" . mysql_real_escape_string($_POST['fldSchool']) . "'"; $fldHighSchoolIds = $fldSelectedSchool; } else { if (!empty($_POST['fldZipCode']) && !empty($_POST['fldDistance'])) { // get all schools within radius of ZIP $zips = $z->get_zips_in_range($_POST['fldZipCode'], $_POST['fldDistance'], _ZIPS_SORT_BY_DISTANCE_ASC, true); $zipsList = implode(',', $zips); $query = sprintf("SELECT * FROM %s WHERE fldZipcode in (%s) AND fldStatus='ACTIVE'", TBL_HS_AAU_TEAM, mysql_real_escape_string($zipsList)); if (!$db->query($query)) { die(mysql_error()); } $numRows = $db->num_rows(); $team_list_id = ''; $db->next_record(); for ($i = 0; $i < $numRows; $i++) { $team_list_id .= $db->f('fldId'); // skips the comma after the last item in the list if ($i != $numRows - 1) { $team_list_id .= ','; } $db->next_record();
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) { echo "Zip code <b>{$key}</b> is <b>{$value}</b> miles away from <b>97214</b>.<br />"; } // One thing you may want to do with this is create SQL from it. For example, // iterate through the array to create SQL that is something like: // WHERE zip_code IN ('93001 93002 93004') // and then use that condition in your query to find all pizza joints or // whatever you're using it for. Make sense? Hope so. echo "<br /><i>get_zips_in_range() executed in <b>" . $z->last_time . "</b> seconds.</i><br />"; } // And one more example of using the class to simply get the information about // a zip code. You can then do whatever you want with it. The array returned
public static function getSchoolsInDistance($zip, $distance) { if (empty($zip)) { return ''; } if ($distance === 'any') { return " AND `fldSchool` != ''"; } if (empty($distance)) { $query = 'SELECT `fldId` FROM ' . TBL_HS_AAU_TEAM . " WHERE `fldZipcode`='" . mysql_real_escape_string($zip) . "' AND `fldStatus`='ACTIVE'"; } else { $z = new zipcode_class(); $zips = $z->get_zips_in_range(mysql_real_escape_string($zip), intval($distance), _ZIPS_SORT_BY_DISTANCE_ASC, true); $fldzip_code = implode(',', $zips); $query = 'SELECT `fldId` FROM ' . TBL_HS_AAU_TEAM . ' WHERE `fldZipcode` IN (' . $fldzip_code . ") AND `fldStatus`='ACTIVE'"; } $db = new DB(); if (!$db->query($query)) { die(mysql_error()); } $schools = array(0); while ($db->next_record()) { $schools[] = $db->f('fldId'); } return ' AND `fldSchool` IN (' . implode(',', $schools) . ')'; }
include_once "inc/common_functions.php"; //for common function include_once "inc/page.inc.php"; $func = new COMMONFUNC(); $db = new DB(); require_once 'zipcode.class.php'; $z = new zipcode_class(); if ($_SESSION['mode'] == "" or $_SESSION['FRONTEND_USER'] == "") { header("Location:index.php"); } $flag = 0; $flag_zip = 0; $page = new Page(); if ($_POST['isSubmit'] == 'save') { $select_college_zipcode = $func->selectTableOrder(TBL_COLLEGE, "fldId,fldZipCode", "fldId", "where fldId='" . $_POST['fldCollegename'] . "'"); $zips = $z->get_zips_in_range($select_college_zipcode['0']['fldZipCode'], $_POST['fldDistance'], _ZIPS_SORT_BY_DISTANCE_ASC, true); $condition = ""; if ($_POST['fldCollegename'] and $_POST['fldDistance'] != 'select') { $fldzip_code = implode(',', $zips); if ($fldzip_code != "") { $condition .= "fldZipCode in (" . $fldzip_code . ") and "; } else { $flag_zip++; } } if ($_POST['fldDistance'] == 'any') { $condition .= "fldZipCode != '' and "; } if ($_POST['fldCollegename'] and $_POST['fldDistance'] == 'select') { //$fldzip_code=implode(',',$zips); //echo $fldzip_code;