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
Pagination allows us to split our results across multiple pages, making our results easier to read. In this way, we give the data to our visitors in bite size chunks instead of overwhelming them with items.
Example Code
catalog.php
$items_per_page = 8;
if (isset($_GET["pg"])) {
$current_page = filter_input(INPUT_GET,"pg",FILTER_SANITIZE_NUMBER_INT);
}
if (empty($current_page)) {
$current_page = 1;
}
$total_items = get_catalog_count($section);
functions.php
function get_catalog_count($category = null) {
$category = strtolower($category);
include("connection.php");
try {
$sql = "SELECT COUNT(media_id) FROM Media";
if (!empty($category)) {
$result = $db->prepare(
$sql
. " WHERE LOWER(category) = ?"
);
$result->bindParam(1,$category,PDO::PARAM_STR);
} else {
$result = $db->prepare($sql);
}
$result->execute();
} catch (Exception $e) {
echo "bad query";
}
$count = $result->fetchColumn(0);
return $count;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Matt Nickolls
9,895 Points2 Answers
-
Amit Kumar
1,063 PointsHow $_GET variable is automatically set on clicking some link like books ,movies,music
Posted by Amit KumarAmit Kumar
1,063 Points2 Answers
-
Dan Avramescu
11,286 Points1 Answer
-
jinhwa yoo
10,042 Points1 Answer
-
Alfredo Prince
6,175 Points0 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