Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="ru">
- <head>
- <meta charset="UTF-8">
- <title>Прогноз погоды</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
- integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
- crossorigin="anonymous">
- </head>
- <body>
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $city = $_POST['city'];
- $weather = $_POST['weather'];
- $temperature = $_POST['temperature'];
- $weatherData = file_get_contents('weather_data.json');
- $weatherData = json_decode($weatherData, true);
- $weatherData[$city] = [
- 'weather' => $weather,
- 'temperature' => $temperature,
- ];
- $weatherData = json_encode($weatherData);
- file_put_contents('weather_data.json', $weatherData);
- }
- ?>
- <div class="container">
- <h1>Прогноз погоды</h1>
- <table class="table table-striped">
- <thead>
- <tr>
- <th>Город</th>
- <th>Погода</th>
- <th>Температура</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $weatherData = file_get_contents('weather_data.json');
- $weatherData = json_decode($weatherData, true);
- ?>
- <?php foreach ($weatherData as $city => $cityData) : ?>
- <tr>
- <td><?php echo $city; ?></td>
- <td><?php echo $cityData['weather']; ?></td>
- <td><?php echo $cityData['temperature']; ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <h2>Добавить новые данные о погоде</h2>
- <form method="post" action="">
- <div class="form-group">
- <label for="city">Город:</label>
- <input type="text" class="form-control" id="city" name="city">
- </div>
- <div class="form-group">
- <label for="weather">Погода:</label>
- <input type="text" class="form-control" id="weather" name="weather">
- </div>
- <div class="form-group">
- <label for="temperature">Температура:</label>
- <input type="text" class="form-control" id="temperature" name="temperature">
- </div>
- <button type="submit" class="btn btn-primary">Добавить данные</button>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement