How can you limit the output of entries in a PHP-based guestbook to only show 12 entries per page?

To limit the output of entries in a PHP-based guestbook to only show 12 entries per page, you can use pagination. Pagination involves dividing the entries into separate pages, each containing a limited number of entries. This allows users to navigate through the entries easily.

<?php
// Assuming $entries is an array containing all guestbook entries

$entriesPerPage = 12;
$totalEntries = count($entries);
$totalPages = ceil($totalEntries / $entriesPerPage);

if (!isset($_GET['page'])) {
    $currentPage = 1;
} else {
    $currentPage = $_GET['page'];
}

$start = ($currentPage - 1) * $entriesPerPage;
$end = $start + $entriesPerPage;

for ($i = $start; $i < $end && $i < $totalEntries; $i++) {
    // Display guestbook entry at index $i
}

// Display pagination links
for ($i = 1; $i <= $totalPages; $i++) {
    echo "<a href='guestbook.php?page=$i'>$i</a> ";
}
?>