
Kemal GENIS - 2025-03-20 07:50:55 -
In reply to message 1 from António Lourenço
<?php
// Number of rows to display per page
$pagePerRow = 10;
// Get the current page number from the URL query string (default to 1 if not set)
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Connect to the MySQL database
$db = mysqli_connect("localhost", "dbuser", "dbpass123", "db_test");
// SQL query to select all rows from the 'users' table
$sql = "SELECT * FROM users";
// Execute the query to get the total number of rows
$totalQuery = mysqli_query($db, $sql); // Corrected: Added $db as the first parameter
$totalRowCount = mysqli_num_rows($totalQuery);
// Calculate the LIMIT clause for pagination
// (page - 1) * pagePerRow gives the starting row, and pagePerRow is the number of rows to fetch
$limitSql = $sql . " LIMIT " . (($page - 1) * $pagePerRow) . ", " . $pagePerRow;
// Execute the query with the LIMIT clause
$limitQuery = mysqli_query($db, $limitSql); // Corrected: Added $db as the first parameter
$limitRows = mysqli_fetch_assoc($limitQuery);
// Calculate the total number of pages needed for pagination
$totalPageCount = ceil($totalRowCount / $pagePerRow); // Corrected: Added $ before pagePerRow
// Include the pagination class file
include_once "pagination.class.php";
// Create an instance of the Pagi class, passing the total page count and the query parameter for pagination
$pagi = new Pagi($totalPageCount, 'page');
// Output the pagination links
echo $pagi->getContent();
?>