Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialZachary Baker
Courses Plus Student 11,504 Pointspagination issues
I fixed my full catalog, but my other pages are not displaying the inventory. Here is a link to my workspace. Please Help!
6 Answers
Hazem mosaad
15,384 PointsYou Have A mistake here:
FILTER_SANITIZENUMBER_INT
Correct Code: FILTER_SANITIZE_NUMBER_INT
Source (http://php.net/manual/en/filter.filters.sanitize.php) // you can check All Filter With Right Style
Zachary Baker
Courses Plus Student 11,504 Pointsphp//
<?php include("inc/functions.php");
$pageTitle = "Full Catalog"; $items_per_page = 8; $section = '';
if (isset($_GET["cat"])) { if ($_GET["cat"] == "books") { $pageTitle = "Books"; $section = "books"; } else if ($_GET["cat"] == "movies") { $pageTitle = "Movies"; $section = "movies"; } else if ($_GET["cat"] == "music") { $pageTitle = "Music"; $section = "music"; } }
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); $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 name 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(items to skip) for the current page // for example: on page 3 with 8 items per page, the offset would be 16 $offset = ($current_page - 1) * $items_per_page;
if (empty($section)) { $catalog = full_catalog_array($items_per_page, $offset); } else { $catalog = category_catalog_array($section,$items_per_page,$offset); }
$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($section)) {
$pagination .= "cat=".$section."&";
}
$pagination .= "pg=$i'>$i</a>";
}
}
$pagination .= "</div>";
include("inc/header.php");
?>
<div class="section catalog page">
<div class="wrapper">
<h1><?php
if ($section != null) {
echo "<a href='catalog.php'>Full Catalog</a> >
";
}
echo $pageTitle; ?></h1>
<?php echo $pagination; ?>
<ul class="items">
<?php
foreach ($catalog as $item) {
echo get_item_html($item);
}
?>
</ul>
<?php echo $pagination; ?>
</div>
</div>
<?php include("inc/footer.php"); ?>
Hazem mosaad
15,384 Pointsok i will check it now :)
Hazem mosaad
15,384 PointsYou Have A mistake here:
FILTER_SANITIZENUMBER_INT
Correct Code: FILTER_SANITIZE_NUMBER_INT
Source (http://php.net/manual/en/filter.filters.sanitize.php) // you can check All Filter With Right Style
Zachary Baker
Courses Plus Student 11,504 PointsThank you. Let me know if you need any of my other code.
Zachary Baker
Courses Plus Student 11,504 PointsThat didn't work, that statement is the one you suggested already. Here is a link to all of my code, can you take a look there.
https://teamtreehouse.com/workspaces/19388712
I apologize for all the trouble and thank you very much for your help.
Hazem mosaad
15,384 PointsI can not enter your work space so you can upload the code here put in organize way so i can read it :) no trouble my friend
Zachary Baker
Courses Plus Student 11,504 PointsI see. I figured out what it was. There was an issue with my random category function on my functions.php file. Once I corrected the issue, it fixed the pagination issue. Thank you again for your help Hazeem, I am really glad that you took the time to help a me out. :-)
Hazem mosaad
15,384 PointsHazem mosaad
15,384 PointsHi Zachary i cannot see the work Space Code Please Put the Code Here So I Can Help :):
Put this => ```php //code
then this ```
Thanks ! Hazem