iwa-panda1

Manage Weather Data by International Weather Agency (Version 1)
Log | Files | Refs

commit 427a28cdcd13a66e6370f612bb400894befad537
parent e6f03bc549ff03bcde2ad2fedba79ca781ac137d
Author: Friedel Schon <[email protected]>
Date:   Tue,  4 Apr 2023 14:55:30 +0200

search data

Diffstat:
Asearchdata.php | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+), 0 deletions(-)

diff --git a/searchdata.php b/searchdata.php @@ -0,0 +1,80 @@ +<html> + +<head> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> +</head> +<?php +include "navbar.php"; +?> + +<body> + <form class="d-flex" action="searchdata.php" method="get"> + <input class="form-control me-2" type="date" name="date-begin" placeholder="Date begin" aria-label="Date begin"> + <input class="form-control me-2" type="date" name="date-end" placeholder="Date end" aria-label="Date end"> + <input class="form-control me-2" type="text" name="station" placeholder="Search" aria-label="Search"> + <button class="btn btn-outline-success" type="submit">Search</button> + </form> + + <?php + $servername = "86.92.67.21"; + $username = "friedel"; + $password = "hailiwa"; + $dbname = "wap2"; + // Create connection + $conn = mysqli_connect($servername, $username, $password, $dbname); + // Check connection + if (!$conn) { + die("Connection failed: " . mysqli_connect_error()); + } + + $sql = "SELECT station_name, date_time, validated, temperature FROM weather_data"; + if (isset($_GET['date-begin']) && $_GET['date-begin']) + $sql .= " WHERE date_time >= ?"; + if (isset($_GET['date-end']) && $_GET['date-end']) + $sql .= " WHERE date_time <= ?"; + if (isset($_GET['station']) && $_GET['station']) + $sql .= " WHERE station_name = ?"; + + $stmt = $conn->prepare($sql); + if (isset($_GET['date-begin']) && $_GET['date-start']) + $stmt->bind_param('s', $_GET['date-begin']); + if (isset($_GET['date-end']) && $_GET['date-end']) + $stmt->bind_param('s', $_GET['date-end']); + if (isset($_GET['station']) && $_GET['station']) { + $stmt->bind_param('d', $_GET['station']); + } + $stmt->execute(); + + $result = $stmt->get_result(); + + // verification logic and $_SESSION start + if ($result->num_rows > 0) { + echo "<table class=\"table table-striped\"> + <thead> + <tr> + <th>Station</th> + <th>Date</th> + <th>Validated</th> + <th>Temperature</th> + </tr> + </thead> + <tbody>"; + while ($row = mysqli_fetch_assoc($result)) { + $link = "/searchdata.php?station=" . $row['station_name']; + echo "<tr>"; + echo "<td><a href='" . $link . "'>" . $row['station_name'] . "</a></td>"; + echo "<td>" . $row['date_time'] . "</td>"; + echo "<td>" . $row['validated'] . "</td>"; + echo "<td>" . $row['temperature'] . "</td>"; + echo "</tr>"; + } + echo " + </tbody> + </table>"; + } else { + echo "No data found."; + } + ?> +</body> + +</html> +\ No newline at end of file