Sulman Posted May 24, 2008 Share Posted May 24, 2008 Hi all, I've searched hi an low for this but can't find it anywhere. I've got pagination working no problem but what I want to be able to do is to break the pages down in to chunks. If there is 200 pages then showing links to all 200 is not good. So what I am trying to do is split the pages in to chunks (5 or 10 etc then adding >> or <<) So if I'm currently on page 8 and my chunks are set to 10 and there are 200 pages the pagination would look like this: 1 2 3 4 5 6 7 8 9 10>> (clicking >> would take you to <<11 12 13...20>> etc). My pagination currently looks like this: <?php //set intial vars $total_pages=21; $chunks=5; $current_page=$_GET[goto]; if($current_page==""){$current_page=1;} //set the from and to //from //I'm stuck here!! for($p=1;$p<=$total_pages;$p++){ if($p==$current_page){ echo "<b>$p</b> "; }else{ echo "<a href=\"".$_SERVER['PHP_SELF']."?goto=$p\">$p</a> "; } } ?> I've tried 101 ways of doing this but keep failing! Anyone help out? thanks Quote Link to comment https://forums.phpfreaks.com/topic/107082-more-pagination/ Share on other sites More sharing options...
.josh Posted May 24, 2008 Share Posted May 24, 2008 Instead of having your page link creation loop count from 1 to $total_pages, have it count from a range, relative to the current page. $range = 5; // number of pages to have before current and after current for ($p = ($current_page - $range); $p <= ($current_page + $range); $p++) { ... } You are going to have to put a condition inside that loop to check if $p is below or above the min or max, of course. If it is, then don't display the link, so it creates 1 2 3 4 5 6 7 8 9 instead of -1 0 1 2 3 4 5 6 7 8 9 As far as the << and >> part: You would add a condition to check if your << marker isn't below or above min or max page. If it's not, you display it. The << would go before the loop, the >> after the loop. Quote Link to comment https://forums.phpfreaks.com/topic/107082-more-pagination/#findComment-548971 Share on other sites More sharing options...
Sulman Posted May 28, 2008 Author Share Posted May 28, 2008 Hi Crayon, Sorry for the delay but thanks for your post. I'll have a look into what you suggest. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/107082-more-pagination/#findComment-551672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.