It's not so practical to explain without examples, or codes, but I will make it simple and the rest of code you have to figure it out yourself.
Basically, there are few variables needed to manipulate the 'pagination'.
For example in a guestbook,
$messagePerPage
$totalMessage
$totalPage
$currentPage
$messageOffset
let's see how we get those variables:
$messagePerPage
// predefined variable, let's say 20 message per page
$messagePerPage = 20;
$totalMessage
$totalMessage = $DB->query_first("SELECT count(id) as count FROM guestbook");
$totalPage
$totalPage = ($totalMessage == 0) ? 0 : ceil($totalMessage / $messagePerPage);
$currentPage
// GET variable, current page number
$currentPage = $_GET['page'];
$messageOffset
$messageOffset = $messagePerPage * $currentPage - $messagePerPage;
then, the query would be:
// for example: if the current page is 1, it would be LIMIT 0, 20, if page is two, it would be LIMIT 20, 20, an so on
$query = $DB->query("SELECT message FROM guestbook ORDER BY date DESC LIMIT $messageOffset, $messagePerPage");
You may wanna previous page and next page too🙂, here it is:
$previousPage
$previousPage = $currentPage - 1;
$nextPage
$nextPage = $currentPage + 1;
and for the navigation link it would be:
echo '<a href="index.php?page=$previousPage">Previous</a> ';
for ($i = 1; $i <= $totalPage; $i++)
{
if ($currentPage == $i) {
// highlight current page
echo '<b>$i</b> ';
} else {
echo '<a href="index.php?page=$i">$i</a> ';
}
}
echo ' <a href="index.php?page=$nextPage">Next</a>';
Write some code, you will understand better.
Hope it helps🙂