Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?
  2. /* Created by Hirsh Agarwal of H2 Micro (www.h2micro.com) */
  3.  
  4. function searchLocation ($longitude, $latitude, $radius){
  5.  
  6. //Fields
  7. $searchResults = array();
  8. //Define Server Variables
  9. $db = ""; //Set Database Name
  10. $host = ""; //Set Database
  11. $dbPassword = ""; //Set Database Password
  12. $dbUsername = ""; //Set Database Username
  13.  
  14. //Connect to mySQL Server
  15. mysql_connect($host, $dbUsername, $dbPassword, $db);
  16. //Select Database
  17. mysql_select_db($db);
  18.  
  19. //Query the database
  20. $result = mysql_query("SELECT
  21. id, (
  22. 3959 * acos (
  23. cos ( radians('$longitude') )
  24. * cos( radians( latitude ) )
  25. * cos( radians( longitude ) - radians('$longitude') )
  26. + sin ( radians('$latitude') )
  27. * sin( radians( latitude ) )
  28. )
  29. ) AS distance
  30. FROM events
  31. HAVING distance < '$radius'
  32. ORDER BY distance
  33. LIMIT 0 , 20;") or die (mysql_error()); //Make sure to update longitude and latitude to reflect the lat/long values as stored in your database
  34. while($row = mysql_fetch_array($result)){
  35. $currentResult = $row['searchVar']; //Update search var as variable that you are searching for
  36. array_push($searchResults, $currentResult)
  37. }
  38.  
  39. return $searchResults;
  40.  
  41. }
  42.  
  43.  
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement