Advertisement
AnggaPratama131294

Untitled

Sep 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2. //create connections
  3. $db_host = "localhost";
  4. $db_user = "root";
  5. $db_pass = "";
  6. $db_name = "dbCuaca";
  7.  
  8. $pdo = new PDO('mysql:host='.$db_host.';dbname='.$db_name, $db_user, $db_pass);
  9.  
  10.  
  11. $city="Jakarta";
  12. $date=1;
  13.  
  14. for ($i=1;$i<2;$i++){
  15. $url="http://api.wunderground.com/api/ef69559783b39217/history_201601".$date."/q/CA/".$city.".json";
  16. $json=file_get_contents($url);
  17. $weather_data[$i]=json_decode($json,true);
  18. //print_r($weather_data[$i]);
  19. $date++;
  20. }
  21.  
  22. ?>
  23.  
  24. <!DOCTYPE html>
  25. <html lang="en">
  26. <head>
  27. <meta charset="utf-8"/>
  28. <title>geogram</title>
  29. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  30. <script src="script.js"></script>
  31. </head>
  32. <body>
  33. <!-- <form action="" method="get">
  34. <input type="text" name="location"/>
  35. <button type="submit">Submit</button>
  36. </form> -->
  37. <br/>
  38. <div>
  39. <table border="1px">
  40. <tr>
  41. <th>Tanggal</th>
  42. <th>Temperatur</th>
  43. <th>Humidity</th>
  44. <th>Pressure</th>
  45. <th>Conditions</th>
  46. </tr>
  47. <?php
  48. for($i=1;$i<2;$i++){
  49. if (!empty($weather_data[$i])) {
  50.  
  51. echo '<tr><td>'.$weather_data[$i]['history']['observations'][0]['date']['pretty'].'</td>';
  52. echo '<td>'.$weather_data[$i]['history']['observations'][0]['tempm'].'</td>';
  53. echo '<td>'.$weather_data[$i]['history']['observations'][0]['hum'].'</td>';
  54. echo '<td>'.$weather_data[$i]['history']['observations'][0]['pressurem'].'</td>';
  55. echo '<td>'.$weather_data[$i]['history']['observations'][0]['conds'].'</td>';
  56. echo '</tr>';
  57.  
  58. }
  59. }
  60. ?>
  61. </div>
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement