Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'DBConnect.php';
- //Checking if any error occured while connecting
- //creating a query
- $stmt = $conn->prepare("SELECT id, station, amount, timer, city FROM reports ORDER BY id desc LIMIT 10");
- //executing the query
- $stmt->execute();
- //binding results to the query
- $stmt->bind_result($id, $station, $amount, $timer, $city);
- $reports = array();
- //traversing through all the result
- while($stmt->fetch()){
- $temp = array();
- $temp['id'] = $id;
- $temp['station'] = $station;
- $temp['amount'] = $amount;
- $temp['timer'] = $timer;
- $temp['formatted_timer'] = humanTiming(strtotime($timer));
- $temp['city'] = $city;
- array_push($reports, $temp);
- }
- //displaying the result in json format
- // TID
- $timeSince = strtotime($reports[0]['timer']);
- function humanTiming ($timeSince)
- {
- $timeSince = time() - $timeSince; // to get the time since that moment
- $timeSince = ($timeSince<1)? 1 : $timeSince;
- $tokens = array (
- 31536000 => 'year',
- 2592000 => 'month',
- 604800 => 'week',
- 86400 => 'day',
- 3600 => 'hour',
- 60 => 'minute',
- 1 => 'second'
- );
- foreach ($tokens as $unit => $text) {
- if ($timeSince < $unit) continue;
- $numberOfUnits = floor($timeSince / $unit);
- return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
- }
- }
- // echo json_encode($reports);
- $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');
- $json_data = json_decode($json,true);
- // echo $json_data['results'];
- foreach ($json['results'] as $name)
- {
- echo "results:". $name['results'] ."\n";
- };
- /*
- foreach ($json_data as $key1 => $value1){
- if($json_data[$key1]["results"]["name"] = "Gothenburg Mariaplan"){
- print_r($json_data[$key1]);
- }
- } */
- echo ("File works");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement