Dealer Locator based on Zip Code. Enter a zip code around which you want to search the database of dealers. Calculates the distance between the Zip Codes and limits the search to distance selected by the user. Requires a standard USPS zip code database with latitude and longitude. Dealer table should contain zip code.
<Html>
<head>
<title>Dealers</title>
</head>
<h5>List of Dealers Nearest to your Zip Code</h5><br><br>
$query = "select * from zipcode where Zipcode = '" . $txtZip . "'";
$result = mysql_query($query,$conn);
$row = mysql_fetch_row($result);
if ($row == false) {
$errflag = true;
$errmsg = "The Zip Code you entered is invalid";
echo "<blockquote>$errmgs</blockquote>";
}
else {
$lat1 = $row[3];
$long1 = $row[4];
}
if ($errflag == false){
$sql = "select zipcode.zipcode, sqrt(power(69.1*(zipcode.latitude - $lat1),2)+ power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) as dist, $dealer.* from $dealer LEFT JOIN zipcode on " ;