home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / phpdealloc.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  2.0 KB  |  55 lines

  1. PHP/MySQL Dealer Locator 
  2.  
  3. 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. 
  4.  
  5.  
  6. <Html> 
  7. <head> 
  8. <title>Dealers</title> 
  9. </head> 
  10. <h5>List of Dealers Nearest to your Zip Code</h5><br><br> 
  11.  
  12. <? 
  13. $errflag = false; 
  14. $conn = mysql_connect( "localhost:3306", "uid", "pass");  
  15. mysql_select_db( "tbcdealers"); 
  16. $query =  "select * from zipcode where Zipcode = '" . $txtZip .  "'"; 
  17. $result = mysql_query($query,$conn); 
  18. $row = mysql_fetch_row($result); 
  19. if ($row == false) { 
  20.   $errflag = true; 
  21.   $errmsg =  "The Zip Code you entered is invalid"; 
  22.   echo  "<blockquote>$errmgs</blockquote>"; 
  23. else { 
  24.    $lat1 = $row[3]; 
  25.    $long1 = $row[4]; 
  26. }   
  27. if ($errflag == false){ 
  28. $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 " ; 
  29.  $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 ; 
  30.  $result = mysql_query($sql,$conn); 
  31.  $count = mysql_num_rows($result); 
  32.  echo  "<blockquote><table border=0>"; 
  33.  for ($i=0; $i < $count; $i++) { 
  34.   echo  "<tr><td>"; 
  35.   $row = mysql_fetch_row($result); 
  36.   echo  "<b>",$row[3], "</b><BR>" ; 
  37.   echo $row[4], "<BR>" ; 
  38.   if ($row[5] <>  ""){ 
  39.     echo $row[5], "<BR>" ; 
  40.   } 
  41.   echo $row[6], "<BR>" ; 
  42.   echo $row[7], "<BR>"; 
  43.   echo $row[8], "<BR>"; 
  44.   $dm = sprintf( "%3.2f",$row[1]); 
  45.   echo  "Distance : $dm miles.<BR><BR>"; 
  46.   echo  "</td></tr>"; 
  47.  } 
  48.  echo  "</table></blockquote>"; 
  49. ?> 
  50. <h6>Note: All distances are in miles and are calculated from the center of the Zip Code</h6> 
  51. </Html> 
  52.  
  53.