Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class page {
- public $element_per_page = 10,
- $nb_links = 2,
- $nb_page = 0,
- $page = 1;
- public function display_page($data) {
- $this->nb_element = count($data);
- $this->nb_page = ceil($this->nb_element / $this->element_per_page);
- if (!empty($_GET['p']) && $_GET['p'] > 0 && $_GET['p'] <= $this->nb_page) {
- $this->page = $_GET['p'];
- }
- return $this->getPagination();
- }
- public function getPagination() {
- $pages = array();
- if ($this->page == $this->nb_links+2) {
- $pages[]['value'] = 1;
- } else if($this->page > $this->nb_links+2) {
- $pages[]['value'] = 1;
- $pages[]['value'] = '…';
- }
- $start = $this->page-$this->nb_links;
- if ($start < 1) {
- $start = 1;
- }
- for ($i=$start; $i<=$this->page+$this->nb_links; $i++) {
- if ($i>0 && $i<=$this->nb_page) {
- $pages[$i]['value'] = $i;
- if ($this->page == $i) {
- $pages[$i]['selected'] = 'selected';
- }
- } else {
- break;
- }
- }
- if ($this->page < $this->nb_page-$this->nb_links-1) {
- $pages[]['value'] = '…';
- }
- if ($this->page <= $this->nb_page-($this->nb_links+1)) {
- $pages[]['value'] = $this->nb_page;
- }
- return $pages;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement