Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "raspberry";
  5. $dbname = "hackathon";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error) {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. $sql = "SELECT token,distance FROM deplacement";
  15. $result = $conn->query($sql);
  16.  
  17. if ($result->num_rows > 0) {
  18. // output data of each row
  19. while($row = $result->fetch_assoc()) {
  20. $dist = intval($row["distance"]);
  21. echo "token: " . $row["token"]. " - total de points: " . $dist. "<br>";
  22. //1€ = 100KM
  23. //1 point = 1 cent
  24. //100 points = 1€ = 100KM
  25. //1 points = 1 KM
  26. if ($dist>1000){
  27. $points = intval(floor($dist/1000));
  28. echo $points;
  29.  
  30.  
  31. $url = 'http://eco.cslabs.be/points/add/';
  32. echo $url;
  33. $data = array('amount' => $points, 'token' => $row["token"]);
  34. var_dump($data);
  35. // use key 'http' even if you send the request to https://...
  36. $options = array('http' => array('method' => 'POST','content' => http_bui$
  37. var_dump($options);
  38. $context = context_create_stream($options);
  39. // $result = file_get_contents($url, false, $context);
  40. $fp = fopen($url, 'r', false, $context);
  41. /* if ($result === FALSE) {
  42. echo "error";
  43. }
  44. */
  45.  
  46. var_dump($fp);
  47.  
  48.  
  49.  
  50.  
  51.  
  52. }
  53. }
  54. } else {
  55. echo "0 results";
  56. }
  57.  
  58. $conn->close();
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement