diff --git a/content/search-results.php b/content/search-results.php index 3cfa52e..4bd5cf1 100644 --- a/content/search-results.php +++ b/content/search-results.php @@ -2,19 +2,38 @@ if (session_status() === PHP_SESSION_NONE) { session_start(); } - -$results = $_SESSION["search_results"] ?? []; + +$all_results = $_SESSION["search_results"] ?? []; $query = $_SESSION["search_query"] ?? ""; +$totalResultsCount = count($all_results); $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10; if (!in_array($limit, [10, 20, 50, 100])) { $limit = 10; } -$results = array_slice($results, 0, $limit); +// Gesamtseitenzahl +$totalPages = max(1, ceil($totalResultsCount / $limit)); + +// Aktuelle Seite auslesen und validieren +$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; +if ($currentPage < 1) { + $currentPage = 1; +} elseif ($currentPage > $totalPages) { + $currentPage = $totalPages; +} + +// Startpunkt im Array berechnen (Offset) +$offset = ($currentPage - 1) * $limit; + +// Nur die Ergebnisse für die aktuelle Seite ausschneiden +$results = array_slice($all_results, $offset, $limit); $resultCount = count($results); ?> +