Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Great, now we need to add pagination links so we can navigate between the pages. I want to add these links both above the results and below the results. But I don’t want to repeat the code, so I’m going to move this code into a variable called $pagination and move it up into the initial code block.
Example Code
$pagination = "<div class=\"pagination\">";
$pagination .= "Pages: ";
for ($i = 1;$i <= $total_pages;$i++) {
if ($i == $current_page) {
$pagination .= " <span>$i</span>";
} else {
$pagination .= " <a href='catalog.php?";
if (!empty($search)) {
$pagination .= "s=".urlencode(htmlspecialchars($search))."&";
} else if (!empty($section)) {
$pagination .= "cat=".$section."&";
}
$pagination .= "pg=$i'>$i</a>";
}
}
$pagination .= "</div>";
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up