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
Now that we have all our basic parameters setup, we’ll need to do a couple calculations.
Example Code
$total_pages = ceil($total_items / $items_per_page);
//limit results in redirect
$limit_results = "";
if (!empty($section)) {
$limit_results = "cat=" . $section . "&";
}
// redirect too-large page numbers to the last page
if ($current_page > $total_pages) {
header("location:catalog.php?"
. $limit_results
. "pg=".$total_pages);
}
// redirect too-small page numbers to the first page
if ($current_page < 1) {
header("location:catalog.php?"
. $limit_results
. "pg=1");
}
//determine the offset (number of items to skip) for the current page
//for example: on page 3 with 8 item per page, the offset would be 16
$offset = ($current_page - 1) * $items_per_page;
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Matt Nickolls
9,895 Points1 Answer
-
Geraldo Hernandez
7,515 Points0 Answers
-
James Fisher
29,163 PointsFrom the transcript/video: If we're on a category page, then we wanna redirect them to a category page.
Posted by James FisherJames Fisher
29,163 Points1 Answer
-
Dan Avramescu
11,286 Points1 Answer
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