loganbest Posted July 17, 2010 Share Posted July 17, 2010 I wrote a pagination script but it displays EVERY page in a block. I'm trying to get it to display only the current page # +/- 5 page numbers. for ($i=0; $i < $this->totalPages; $i++) { $pagesEndCount = $i + 1; if(($i-10) < $this->currentPage || $i >= $this->currentPage) { if($i != $this->currentPage) { printf('<a href="'."%s?$this->pagingURL=%d%s", $this->thisPage, $i, $pagingURL .'">'.$pagesEndCount."</a>"); }else{ echo("$this->beforeCurrentPage$pagesEndCount$this->afterCurrentPage"); } if($i != $this->totalPages-1) echo($this->linkDelimiter); } Quote Link to comment Share on other sites More sharing options...
mrdamien Posted July 17, 2010 Share Posted July 17, 2010 The starting number would be: max($this->currentPage-5, 0); The ending page number would be: min($this->currentPage+5, $this->totalPages) so you can change your loop: $start = max($this->currentPage-5, 0); $end = min($this->currentPage+5, $this->totalPages); for ($i=$min; $i < $max; $i++) { if($i != $this->currentPage) { ... }else{ ... } } Quote Link to comment Share on other sites More sharing options...
loganbest Posted July 18, 2010 Author Share Posted July 18, 2010 Did you mean to put this? for ($i=$start; $i < $end; $i++) { Quote Link to comment Share on other sites More sharing options...
jimbob72 Posted July 26, 2010 Share Posted July 26, 2010 Hi Did you get this to work?? as I have exactly the same base code (from cartweaver php program) and would like to compact the page number results. Please post the final code result if possible. Many Thanks Jimbob72 Quote Link to comment 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.