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 trialChris Sehnert
30,857 PointsIntegrating PHP with Databases...."Pagination Challenge"
Task 2 asks for 3 things......(which means there is no way of knowing which of the three is not being completed correctly......poor testing practice....)....
Move the code into the function....seems easy enough .....put the curly braces around the specified code......
Return the $pagination variable return $pagination; //DONE!
Change the echo on the final line to call the function instead of the variable. Make sure you pass the four variables: \$total_pages, \$current_page, \$section, \$search.
I don't know what else to do here aside from what I've tried.....which is to call the function......I've tried tried using "\$total_pages, \$current_page, \$section, \$search"...for arguments .....god knows what the backslashes are for....but there are no other variables given.....I've tried making up arguments......where $total_pages and $current_page were integers and the other two were strings......
I've tried all of these things while echo trying to echo the function...... I've assigned the function to a variable, since it returns the $pagination variable.... I've tried echoing out that new variable......
I'm going to be upset if this is just a poorly wrought question.......and there's been seemingly no other questions asked about this challenge......soooo....geee....I guess i'm DUMB!
<?php
include "pagination.php";
/* add function here */
function pagination($total_pages, $current_page, $section, $search) {
/* setting pagination variable */
$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>";
return $pagination;
}
/* displaying the pagination */
$newPag = pagination(\$total_pages, \$current_page, \$section, \$search);
echo $newPag;
1 Answer
Chris Sehnert
30,857 PointsAsked and answered........poorly written question......problem solved!