Created
April 28, 2016 21:10
-
-
Save BIGjuevos/1770860e6bb6912360ef91c0f7ffc0ef to your computer and use it in GitHub Desktop.
Pagination Algo in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pageCount = ceil( $counts['paginated'] / 10 ); | |
$low = max(0, $currentPage - 5); | |
if ( $pageCount > 10 ) { | |
$high = $currentPage + 5; | |
} else { | |
$high = $pageCount - 1; | |
} | |
$high = (int)$high; | |
$pages = []; | |
for ( $i = $low; $i <= $high; $i++ ) { | |
$pages[] = [ | |
'pageNum' => $i, | |
'displayPageNum' => $i + 1, | |
'active' => $i === $currentPage, | |
]; | |
} | |
$this->view->addData("currentPage", $currentPage); | |
$this->view->addData("pages", $pages); | |
$this->view->addData("counts", $counts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment