Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body>
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  7. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  8. <div class = "container">
  9. <nav class = "navbar navbar-inverse">
  10. <div class = "container-fluid">
  11. <div class = "navbar-header">
  12. <a class = "navbar-brand" href = "home.html">YardSaleMapper.com</a>
  13. </div>
  14. <ul class = "nav navbar-nav">
  15. <li><a href = "home.html">Go Home</a></li>
  16. <li class = "active"><a href = "viewSales.php">View Sales</a></li>
  17. <li><a href = "addSale.html">Publish your Sale</a></li>
  18. </ul>
  19. </div>
  20. </nav>
  21. <h3>Enter Starting Point</h3>
  22. <hr/>
  23. <form method = "post" id = "myForm">
  24. <div class = "col-md-2">
  25. <div class = "form-group">
  26. Street:
  27. <input class = "form-control" type = "text" name = "start_street" ng-model = "ss" required/>
  28. </div>
  29. </div>
  30. <div class = "col-md-2">
  31. <div class = "form-group">
  32. City:
  33. <input class = "form-control" type = "text" name = "start_city" ng-model = "ss" required/>
  34. </div>
  35. </div>
  36. <div class = "col-md-2">
  37. <div class = "form-group">
  38. State (EX: PA):
  39. <input class = "form-control" type = "text" name = "start_state" ng-model = "ss" maxlength="2" required/>
  40. </div>
  41. </div>
  42. <div class = "col-md-2">
  43. <div class = "form-group">
  44. ZIP
  45. <input class = "form-control" type = "text" name = "start_zip" ng-model = "ss" maxlength="5" required/>
  46. </div>
  47. </div>
  48. <div class = "col-md-2">
  49. <div class = "form-group">
  50. Within <select type = "text" name = "distance" required class = "form-control">
  51. <option value = 5>5</option>
  52. <option value = 10>10</option>
  53. <option value = 15>15</option>
  54. <option value = 20>20</option>
  55. <option value = 25>25</option>
  56. </select>
  57. Miles
  58. </div>
  59. </div>
  60. <div class = "col-md-2">
  61. <div class = "form-group">
  62. &nbsp
  63. <button class ="btn btn-primary btn-block" id = "submit" type = "submit" name = "submit">Submit</button>
  64. </div>
  65. </div>
  66. </form>
  67. </div>
  68.  
  69. <script id = "source" language = "javascript" type = "text/javascript">
  70. $(function() {
  71. $('#submit').on('click', function() {
  72. $.ajax({
  73. url: 'getSales.php',
  74. method: 'post',
  75. data: $("#myForm").serialize(),
  76. dataType: 'json',
  77. success: function(data) {
  78. console.log(data);
  79. }
  80. })
  81. })
  82. });
  83. </script>
  84.  
  85. </body>
  86. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  87. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  88. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  89.  
  90.  
  91. </html>
  92.  
  93. <?php
  94. $servername = "localhost";
  95. $username = "username";
  96. $password = "password";
  97. $dbname = "yardsales";
  98.  
  99. $data = array();
  100.  
  101. // Create connection
  102. $conn = new mysqli($servername, $username, $password, $dbname);
  103. // Check connection
  104. if ($conn->connect_error) {
  105. die("Connection failed: " . $conn->connect_error);
  106.  
  107. }
  108.  
  109. $street = $_POST["start_street"];
  110. $city = $_POST["start_city"];
  111. $state = $_POST["start_state"];
  112. $zip = $_POST["start_zip"];
  113. $dist = $_POST["distance"];
  114.  
  115. $address = $street . ", " . $city . ", " . $state . ", " . $zip;
  116.  
  117. $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
  118.  
  119. // Convert the JSON to an array
  120. $geo = json_decode($geo, true);
  121.  
  122. if ($geo['status'] == 'OK') {
  123. // Get Lat & Long
  124. $lat = $geo['results'][0]['geometry']['location']['lat'];
  125. $long = $geo['results'][0]['geometry']['location']['lng'];
  126.  
  127. }
  128.  
  129. $sql = "SELECT street, city, state, zip, county, sdate, edate,
  130. stime, etime, description, 69 * vincenty($lat, $long, lat, lon) AS distance from
  131. addresses where 69 * vincenty($lat, $long, lat, lon) < $dist";
  132.  
  133. $result = $conn->query($sql);
  134.  
  135. while($row = $result->fetch_assoc()) {
  136. $data[] = $row;
  137. //print_r($row);
  138. }
  139.  
  140. echo json_encode($data);
  141.  
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement