Hello, I have a products page which lists the pics of the products. I added pagination with bootstrap classes. I have 10 products in my database. I want to limit per page to display only 6 so then the second page should display 4. The issue im facing now is that the second page button doesn't "change" to the second page. but if i click >> button it does change.
pic for visualization:
code:
$per_pageAll = 6;
if (isset($_GET["page"]))
$pageAll = $_GET["page"];
else
$pageAll = 1;
$start_fromAll = ($pageAll-1) * $per_pageAll;
$stmtAll = $conn->prepare("SELECT id, name, price, type, img FROM tbl LIMIT $start_fromAll, $per_pageAll");
$stmtAll->execute();
$resultAll = $stmtAll->fetchAll();
code in html part:
<?php
$stmtA = $conn->prepare("SELECT * FROM tbl_products_a154287");
$stmtA->execute();
$resultA = $stmtA->fetchAll();
$total_recordsAll = count($resultA);
$total_pagesAll = ceil($total_recordsAll / $per_pageAll);
$total_recordsAll = count($resultAll);
$total_pagesAll = ceil($total_recordsAll / $per_pageAll);
if ($pageAll==1) { ?>
<li class="disabled"><span aria-hidden="true">«</span></li>
<?php } else { ?>
<li><a href="products.php?page=<?php echo $pageAll-1 ?>" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
<?php
}
for ($i=1; $i<=$total_pagesAll; $i++)
if ($i == $pageAll)
echo "<li class=\"active\"><a href=\"products.php?pageAll=$i\">$i</a></li>";
else
echo "<li><a href=\"products.php?pageAll=$i\">$i</a></li>";
?>
<?php if ($pageAll==$total_pagesAll) { ?>
<li class="disabled"><span aria-hidden="true">»</span></li>
<?php } else { ?>
<li><a href="products.php?page=<?php echo $pageAll+1 ?>" aria-label="Previous"><span aria-hidden="true">»</span></a></li>
<?php } ?>
I am not sure what i did wrong. I only modified the names. thanks in advance.