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
We have all the variables set for our pagination, so let’s start adding our limits. We are going to be limiting the number of products we show on a page, so we want to add limits to our catalog calls. This will tell the database to only return a limited number of items. Again, reducing the amount of data the page has to handle.
Example Code
function category_catalog_array($category, $limit = null, $offset = 0) {
include("connection.php");
$category = strtolower($category);
try {
$sql = "SELECT media_id, title, category,img
FROM Media
WHERE LOWER(category) = ?
ORDER BY
REPLACE(
REPLACE(
REPLACE(title,'The ',''),
'An ',
''
),
'A ',
''
)";
if (is_integer($limit)) {
$results = $db->prepare($sql . " LIMIT ? OFFSET ?");
$results->bindParam(1,$category,PDO::PARAM_STR);
$results->bindParam(2,$limit,PDO::PARAM_INT);
$results->bindParam(3,$offset,PDO::PARAM_INT);
} else {
$results = $db->prepare($sql);
$results->bindParam(1,$category,PDO::PARAM_STR);
}
$results->execute();
} catch (Exception $e) {
echo "Unable to retrieved results";
exit;
}
$catalog = $results->fetchAll();
return $catalog;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Dylan Fabian Bento
18,458 Points0 Answers
-
Alex Bauer
9,426 Points1 Answer
-
György Varga
19,198 Points0 Answers
-
PLUS
Anthony Erdman
Courses Plus Student 5,021 Points1 Answer
-
casthrademosthene
6,275 Points0 Answers
-
Zack Ball
4,958 Points2 Answers
-
Zack Ball
4,958 Points1 Answer
-
Qasim Hafeez
12,731 PointsClicking on categories throws "too many redirects" error
Posted by Qasim HafeezQasim Hafeez
12,731 Points1 Answer
-
MOD
Jonathan Grieve
Treehouse Moderator 91,254 Points0 Answers
-
PLUS
Zachary Baker
Courses Plus Student 11,504 Points3 Answers
-
PLUS
janeporter
Courses Plus Student 23,471 Points3 Answers
-
Nathan LaBrake
24,088 Points3 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