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); } Link to comment https://forums.phpfreaks.com/topic/208050-pagination/ 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{ ... } } Link to comment https://forums.phpfreaks.com/topic/208050-pagination/#findComment-1087610 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++) { Link to comment https://forums.phpfreaks.com/topic/208050-pagination/#findComment-1087654 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 Link to comment https://forums.phpfreaks.com/topic/208050-pagination/#findComment-1091409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.