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 trial
Lans Lister
7,492 PointsPaginating
Hi,
Ive been waiting on the PHP lesson to come up for awhile now on Paginating and was just wondering if anyone knew where I could learn this ASAP. I would love to be able to display like 6 array items each page so that it isn't just one big list of items.
Thanks in advance :)
5 Answers
Randy Hoyt
Treehouse Guest TeacherI'm happy to announce that the two badges for Paginating a List have now been released:
Lans Lister
7,492 PointsJust what i needed!! Great, thanks Randy!
Jack Vliegendhart
6,581 PointsTo put it simple you could loop an array from $x to $y and for the next page from $x+31 to $y+60 then the next from $x+61 to $y+90
To write an example:
$page = $_GET['page'];
$itemsonpage = 30;
$producs = array('t-shirt', 'cow', 'chicken'); // and some more...
// now I know cow & chicken are not products but just to give an example and I assure you they are not harmed this way ;)
$end = $itemsonpage * $page;
$start = $end - $itemsonpage;
for($i = 0; $i < $itemsonpage; $i++) {
echo $product[$start+$i];
}
I wrote this quickly so there might be a little mistake in it. But basically you get the page nr and multiply it with the items on the page. then you can calculate the nr in the array from there.
Hope this helps ;)
Randy Hoyt
Treehouse Guest TeacherWe're very close to having these next two stages ready so we can finish out the project. We're hoping to release them today; if not, then it will be next week. Stay tuned!
Jake White
41,730 PointsI've been waiting for this one too. I've got 80 items right now for one of my product categories. Been checking every day to see when it will post.
Lans Lister
7,492 Points@Jack Vliegendhart - Thanks for your reply, I still haven't got there but I appreciate the help :)
@Randy Hoyt - Thanks for letting me know, I can now stop worrying about if i'll ever finish my project :P
James Barnett
39,199 PointsJames Barnett
39,199 PointsMaybe Randy Hoyt can give us on update on the timeframe for that badge.