I have tried lot of php pagination, But this is superb, very easy to use and so short.
connection.php
$db_username = 'root'; // Your MYSQL Username.
$db_password = ''; // Your MYSQL Password.
$db_name = 'database_name_here'; // Your Database name.
$db_host = 'localhost';
$conDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('Error: Could not connect to database.');
include_once('connection.php');
include_once('functions.php');
$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]);
if ($page <= 0) $page = 1;
$per_page = 10; // Set how many records do you want to display per page.
$startpoint = ($page * $per_page) - $per_page;
$statement = "`records` ORDER BY `id` ASC"; // Change `records` according to your table name.
$results = mysqli_query($conDB,"SELECT * FROM {$statement} LIMIT {$startpoint} , {$per_page}");
if (mysqli_num_rows($results) != 0) {
// displaying records.
while ($row = mysqli_fetch_array($results)) {
echo $row['name'] . ' ';
}
} else {
echo "No records are found.";
}
// displaying paginaiton.
echo pagination($statement,$per_page,$page,$url='?');
0 comments