Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. include 'DBConnect.php';
  4.  
  5.  
  6. //Checking if any error occured while connecting
  7.  
  8. //creating a query
  9. $stmt = $conn->prepare("SELECT id, station, amount, timer, city FROM reports ORDER BY id desc LIMIT 10");
  10.  
  11. //executing the query
  12. $stmt->execute();
  13.  
  14. //binding results to the query
  15. $stmt->bind_result($id, $station, $amount, $timer, $city);
  16.  
  17. $reports = array();
  18.  
  19. //traversing through all the result
  20. while($stmt->fetch()){
  21. $temp = array();
  22. $temp['id'] = $id;
  23. $temp['station'] = $station;
  24. $temp['amount'] = $amount;
  25. $temp['timer'] = $timer;
  26. $temp['formatted_timer'] = humanTiming(strtotime($timer));
  27. $temp['city'] = $city;
  28.  
  29. array_push($reports, $temp);
  30. }
  31. //displaying the result in json format
  32.  
  33. // TID
  34.  
  35.  
  36.  
  37. $timeSince = strtotime($reports[0]['timer']);
  38.  
  39.  
  40. function humanTiming ($timeSince)
  41. {
  42.  
  43. $timeSince = time() - $timeSince; // to get the time since that moment
  44. $timeSince = ($timeSince<1)? 1 : $timeSince;
  45. $tokens = array (
  46. 31536000 => 'year',
  47. 2592000 => 'month',
  48. 604800 => 'week',
  49. 86400 => 'day',
  50. 3600 => 'hour',
  51. 60 => 'minute',
  52. 1 => 'second'
  53. );
  54.  
  55. foreach ($tokens as $unit => $text) {
  56. if ($timeSince < $unit) continue;
  57. $numberOfUnits = floor($timeSince / $unit);
  58. return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  59. }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. // echo json_encode($reports);
  66.  
  67.  
  68.  
  69. $json = file_get_contents('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=57.6890405,11.9122761&sensor=true&key=AIzaSyD2Q1lSS-EWu4XPvgvxvfrNZdiE8NYgdpU&rankby=distance&types=transit_station');
  70.  
  71. $json_data = json_decode($json,true);
  72.  
  73. // echo $json_data['results'];
  74.  
  75. foreach ($json['results'] as $name)
  76. {
  77. echo "results:". $name['results'] ."\n";
  78. };
  79.  
  80.  
  81. /*
  82.  
  83. foreach ($json_data as $key1 => $value1){
  84. if($json_data[$key1]["results"]["name"] = "Gothenburg Mariaplan"){
  85.  
  86. print_r($json_data[$key1]);
  87. }
  88.  
  89. } */
  90.  
  91.  
  92.  
  93. echo ("File works");
  94.  
  95.  
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement