PX : code

PHP/MySQL Dealer Locator by Durga Prasad Koka
Rating: 5.00
Download this code


<Html>
<head>
<title>Dealers</title>
</head>
<h5>List of Dealers Nearest to your Zip Code</h5><br><br>

<?
$errflag = false;
$conn = mysql_connect("localhost:3306","uid","pass"); 
mysql_select_db("tbcdealers");
$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 " ;
 $sql = $sql . " $dealer.zip = zipcode.zipcode where  sqrt(power(69.1*(zipcode.latitude - $lat1),2)+ power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) < " . $cboDist ;
 $result = mysql_query($sql,$conn);
 $count = mysql_num_rows($result);
 echo "<blockquote><table border=0>";
 for ($i=0; $i < $count; $i++) {
  echo "<tr><td>";
  $row = mysql_fetch_row($result);
  echo "<b>",$row[3],"</b><BR>" ;
  echo $row[4],"<BR>" ;
  if ($row[5] <> ""){
    echo $row[5],"<BR>" ;
  }
  echo $row[6],"<BR>" ;
  echo $row[7],"<BR>";
  echo $row[8],"<BR>";
  $dm = sprintf("%3.2f",$row[1]);
  echo "Distance : $dm miles.<BR><BR>";
  echo "</td></tr>";
 }
 echo "</table></blockquote>";
}
?>
<h6>Note: All distances are in miles and are calculated from the center of the Zip Code</h6>
</Html>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.