How can PHP be used to automatically generate page numbers for navigating through multiple pages of database entries?

To automatically generate page numbers for navigating through multiple pages of database entries, you can use PHP to calculate the total number of pages based on the total number of entries and the desired number of entries per page. Then, you can create links to each page using a loop to iterate through the total number of pages.

<?php
// Assuming $totalEntries contains the total number of database entries
$entriesPerPage = 10; // Number of entries to display per page
$totalPages = ceil($totalEntries / $entriesPerPage);

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