Skip to content

Instantly share code, notes, and snippets.

@BIGjuevos
Created April 28, 2016 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BIGjuevos/1770860e6bb6912360ef91c0f7ffc0ef to your computer and use it in GitHub Desktop.
Save BIGjuevos/1770860e6bb6912360ef91c0f7ffc0ef to your computer and use it in GitHub Desktop.
Pagination Algo in PHP
<?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