Advertisement
qberik

Untitled

Feb 27th, 2023
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Прогноз погоды</title>
  6.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
  7.           integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
  8.           crossorigin="anonymous">
  9. </head>
  10. <body>
  11.  
  12. <?php
  13. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  14.     $city = $_POST['city'];
  15.     $weather = $_POST['weather'];
  16.     $temperature = $_POST['temperature'];
  17.  
  18.     $weatherData = file_get_contents('weather_data.json');
  19.     $weatherData = json_decode($weatherData, true);
  20.  
  21.     $weatherData[$city] = [
  22.         'weather' => $weather,
  23.         'temperature' => $temperature,
  24.     ];
  25.  
  26.     $weatherData = json_encode($weatherData);
  27.     file_put_contents('weather_data.json', $weatherData);
  28. }
  29. ?>
  30.  
  31. <div class="container">
  32.     <h1>Прогноз погоды</h1>
  33.  
  34.     <table class="table table-striped">
  35.         <thead>
  36.         <tr>
  37.             <th>Город</th>
  38.             <th>Погода</th>
  39.             <th>Температура</th>
  40.         </tr>
  41.         </thead>
  42.         <tbody>
  43.         <?php
  44.           $weatherData = file_get_contents('weather_data.json');
  45.           $weatherData = json_decode($weatherData, true);
  46.         ?>
  47.         <?php foreach ($weatherData as $city => $cityData) : ?>
  48.             <tr>
  49.                 <td><?php echo $city; ?></td>
  50.                 <td><?php echo $cityData['weather']; ?></td>
  51.                 <td><?php echo $cityData['temperature']; ?></td>
  52.             </tr>
  53.         <?php endforeach; ?>
  54.         </tbody>
  55.     </table>
  56.  
  57.     <h2>Добавить новые данные о погоде</h2>
  58.     <form method="post" action="">
  59.         <div class="form-group">
  60.             <label for="city">Город:</label>
  61.             <input type="text" class="form-control" id="city" name="city">
  62.         </div>
  63.         <div class="form-group">
  64.             <label for="weather">Погода:</label>
  65.             <input type="text" class="form-control" id="weather" name="weather">
  66.         </div>
  67.         <div class="form-group">
  68.             <label for="temperature">Температура:</label>
  69.             <input type="text" class="form-control" id="temperature" name="temperature">
  70.         </div>
  71.         <button type="submit" class="btn btn-primary">Добавить данные</button>
  72.     </form>
  73. </div>
  74.  
  75.  
  76. </body>
  77. </html>
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement