Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Getting Specific with Queries 4:38
- Filtering Data by Category 6:28
- Filtering Data 3 objectives
- Setting Up Pagination Variables 7:43
- Calculations and Links 5:32
- Variable and Calculations 5 questions
- Setting LIMITs 4:52
- LIMIT and OFFSET 2 objectives
- Adding Pagination Links 7:05
- Pagination Function 2 objectives
- Challenge 1:08
- Simplifying with a Function 10:24
- Pagination 5 questions

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
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 up-
Joy Manuel
6,464 Points1 Answer
-
PLUS
Zachary Baker
Courses Plus Student 11,504 Points0 Answers
-
PLUS
Zachary Baker
Courses Plus Student 11,504 Points0 Answers
-
PLUS
Zachary Baker
Courses Plus Student 11,504 Points2 Answers
-
cleancoder
8,307 Points0 Answers
-
lior babi
9,075 PointsWhy don't you use ob_start() and ob_get_clean() for $pagination?
Posted by lior babilior babi
9,075 Points0 Answers
-
Unsubscribed User
48,988 Points5 Answers
View all discussions for this video
Related 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