iwa-panda1

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

commit a1caada19a1f4f58b9f0de43a41503c886ee106b
parent 754782f0764349c261a583223531798e4abab412
Author: LennartSchroot <[email protected]>
Date:   Sun, 16 Apr 2023 16:07:55 +0200

groetjes aan denny

Diffstat:
Msearchdata.php | 38+++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/searchdata.php b/searchdata.php @@ -10,8 +10,8 @@ error_reporting(0); </head> <body> <form class="d-flex" action="searchdata.php" method="get"> - <input class="form-control me-2" type="text" name="date-begin" placeholder="Date begin (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" required> - <input class="form-control me-2" type="text" name="date-end" placeholder="Date end (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" required> + <input class="form-control me-2" type="text" name="date-begin" placeholder="Date begin (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}"> + <input class="form-control me-2" type="text" name="date-end" placeholder="Date end (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}"> <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> @@ -20,19 +20,31 @@ error_reporting(0); $conn = $connect->getConn(); $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 = ?"; + if (isset($_GET['date-begin']) && $_GET['date-begin']) { + $sql .= " WHERE date_time >= ?"; + if (isset($_GET['date-end']) && $_GET['date-end']) { + $sql .= " AND date_time <= ?"; + } + } elseif (isset($_GET['date-end']) && $_GET['date-end']) { + $sql .= " WHERE date_time <= ?"; + } + if (isset($_GET['station']) && $_GET['station']) { + $sql .= " WHERE station_name = ?"; + } + + $dateEnd = $_GET['date-end'] . "%"; + $dateBegin = $_GET['date-begin'] . "%"; + + echo $sql; +// echo $dateBegin; +// echo $dateEnd; $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']) { + if (isset($_GET['date-begin'])) + $stmt->bind_param('s', $dateBegin); + if (isset($_GET['date-end'])) + $stmt->bind_param('s', $dateEnd); + if (isset($_GET['station'])) { $stmt->bind_param('d', $_GET['station']); }