Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. class PickupPoint {
  4.     public $loc_id = 0;
  5.     public $latitude = 1.0;
  6.     public $longitude = 10.0;
  7.     public $points = 0;
  8. }
  9.  
  10. $loc = new PickupPoint();
  11. $loc->loc_id = 0;
  12. $loc->latitude = 5.0;
  13. $loc->longitude = 10.0;
  14. $loc->points = 0;
  15.  
  16. $locs = array($loc, $loc); //add more points
  17. echo json_encode($locs);
  18.  
  19. $servername = "localhost";
  20. $username = "starfeesh";
  21. $password = "norissa9";
  22. $dbname = "uniridersdb";
  23.  
  24. // Create connection
  25. $conn = new mysqli($servername, $username, $password, $dbname);
  26. // Check connection
  27. if ($conn->connect_error) {
  28.     die("Connection failed: " . $conn->connect_error);
  29. }
  30.  
  31. $sql = "SELECT loc_id, latitude, longitude, points FROM locations";
  32. $result = $conn->query($sql);
  33.  
  34. if ($result->num_rows > 0) {
  35.     // output data of each row
  36.     while($row = $result->fetch_assoc()) {
  37.         $loc = new PickupPoint();
  38.         $loc->loc_id = $row["loc_id"];
  39.         $loc->latitude = $row["latitude"];
  40.         $loc->longitude = $row["longitude"];
  41.         $loc->points = $row["points"];
  42.     }
  43. } else {
  44.     echo "0 results";
  45. }
  46. $conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement