Untitled
unknown
plain_text
2 months ago
1.1 kB
4
Indexable
<?php header("Content-Type: application/json"); $host = "localhost"; $dbname = "internet"; $username = "internet"; $password = ""; $periods = [ "24h" => "NOW() - INTERVAL 1 DAY", "1m" => "NOW() - INTERVAL 1 MONTH", "3m" => "NOW() - INTERVAL 3 MONTH", "6m" => "NOW() - INTERVAL 6 MONTH", "12m" => "NOW() - INTERVAL 12 MONTH", "all" => "1900-01-01" // Henter alt ]; try { $pdo = new mysqli($host, $username, $password, $dbname); if ($pdo->connect_error) { die(json_encode(["error" => "Tilkoblingsfeil: " . $pdo->connect_error])); } $data = []; foreach ($periods as $key => $value) { $stmt = $pdo->prepare("SELECT timestamp, status FROM surveillance WHERE timestamp >= $value ORDER BY timestamp ASC"); $stmt->execute(); $result = $stmt->get_result(); $data[$key] = []; while ($row = $result->fetch_assoc()) { $data[$key][] = $row; } } echo json_encode($data); } catch (Exception $e) { echo json_encode(["error" => $e->getMessage()]); } ?>
Editor is loading...
Leave a Comment