So habe ich ein einfaches Paginierungssystem auf meiner Website. Aber es gibt ein Problem mit meiner Berechnung für die nächste Seite. Immer wenn die Seite auf Seite 2 ist, ist die nächste Seite 13 statt 3. Ich habe die Berechnung getestet und es kommt immer mit 3 als Ergebnis heraus. Hier ist mein Code:PHP - Paginierung falsch gezählt
<?php
$applied_filters = array("parent" => null, "child" => null);
if(isset($_GET['cat'])) {
$applied_filters["parent"] = $_GET['cat'];
if(isset($_GET['sub']))
$applied_filters["child"] = $_GET['sub'];
}
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$products_per_page = 9;
$start_from = ($page-1) * $products_per_page;
$pagination_url = "winkel.php?";
if($applied_filters["parent"] != null) {
$pagination_url .= "cat=" . $applied_filters["parent"];
if($applied_filters["child"] != null) {
$pagination_url .= "&sub=" . $applied_filters["child"] . "&page=";
} else {
$pagination_url .= "&page=";
}
} else {
$pagination_url .= "page=";
}
echo $page . '<br>'; // shows 2
$nextpage = $page + 1; //shows 3
echo $nextpage;
?>
<ul class="pagination">
<?php if($page > 1) { ?>
<li><a href="<?= $pagination_url .= $page - 1; ?>">«</a>
</li>
<?php } ?>
<li class="active"><a href="#"><?= $page ?></a>
</li>
<?php if($page < $max_pages) { echo $nextpage; // shows 3?>
<li><a href="<?= $pagination_url .= $nextpage; // shows 13 ?>">»</a>
</li>
<?php } ?>
ich auch einige URL-Code für die Filter auf meiner Website haben:
<?php
// link filters
if(isset($_GET['cat'])) {
if(isset($_GET['cat']) && isset($_GET['sub'])) {
if($_GET['cat'] != "alles")
$result_products = $db->get_by_cat("products", $_GET['cat'], $_GET['sub'], $start_from, $products_per_page);
} else if (isset($_GET['cat'])) {
if($_GET['cat'] != "alles")
$result_products = $db->get_by_cat("products", $_GET['cat'], null, $start_from, $products_per_page);
}
}
if(isset($_POST['clearbrand'])) {
unset($_POST['brandfilter']);
unset($_POST['applybrand']);
}
$filtered_brands = null;
if(isset($_POST['brandfilter'])) $filtered_brands = $_POST['brandfilter'];
// form filters
if(isset($_POST['applybrand'])) {
if(isset($_GET['cat'])) {
$result_products = $db->get_by_checkbox("products", "brand", $_POST['brandfilter'], $_GET);
} else {
$result_products = $db->get_by_checkbox("products", "brand", $_POST['brandfilter']);
}
}
?>
So weiß jemand, warum meine Paginierung zählt 2-13? Vielen Dank im Voraus
Nun, die Tatsache, dass Sie ständig etwas _appending_ Sachen '$ pagination_url' haben könnte damit zu tun sind, nicht wahr? – CBroe