How can PHP be used to display multiple pages of forum posts with links to each page?
To display multiple pages of forum posts with links to each page, you can use PHP to calculate the total number of pages based on the total number of posts and the desired number of posts per page. Then, you can dynamically generate links to each page using a loop to iterate through the pages.
<?php
// Total number of posts
$totalPosts = 100;
// Posts per page
$postsPerPage = 10;
// Calculate total number of pages
$totalPages = ceil($totalPosts / $postsPerPage);
// Display links to each page
for ($i = 1; $i <= $totalPages; $i++) {
echo "<a href='forum.php?page=$i'>Page $i</a>";
}
?>