"Code" PHP paging class
The following is a page I write my own class, can make simple changes
[PHP]
get = (int) $_get[' startrow ']; $this->post = (int) $_post[' pagenums ']; $this->pagesize = $pageSize; $this Pagetotal = Ceil ($total/$pageSize), switch ($_get[' method ') {default: $this->startrow = 1; $this->offset = 0;break Case ' first ': $this->first (); Break;case ' previous ': $this->previous (); Break;case ' Next ': $this->next (); Break;case ' last ': $this->last (); /*** Home Method **/public function first () {$this->startrow = 1; $this->offset = ($this->startrow-1) * $this->pagesi Ze;} /*** Previous method **/public function previous () {$this->startrow = $this->get-1;if ($this->startrow < 1) {$this StartRow = 1;} $this->offset = ($this->startrow-1) * $this->pagesize;} /*** Next Page Method **/public function next () {$this->startrow = $this->get + 1;if ($this->startrow > $this Pagetotal) {$this->startrow = $this->pagetotal;} $this->offset = ($this->startrow-1) * $this->pagesize;} /*** Final Page Method **/public function last () {$this->startrow = $this->pagetotal; $this->offset = ($this->startrow-1) * $this->pagesize;} /*** drop-down Menu page * * @return int*/public function numpages () {if ($this->post) {$pageNums = "$this->post"; $this->startrow = $this->post; $this->offset = ($this->post-1) * $this->pagesize;} for ($i = 1; $i <= $this->pagetotal; $i + +) {if ($i! = $this->post) {$pageNums. = "$i";}} return $pageNums;} /*** Current Page * * @return int*/public function noncepage () {if ($this->post) {return $this->startrow = $this->post;} else {return $this->startrow = $this->startrow;}}}
Call Method:
[PHP]
$total = $total->total ();//total record $pagesize = 15;//The record displayed per page $pager = new Pager ($total, $pageSize); if ($pager->post) {$ StartRow = $pager->noncepage ();} $startRow = $pager->startrow; $pager->numpages () $article->query ("Select * from ' categories ' as C, ' articles ' As n WHERE c.id = N.pidorder by n.id DESC LIMIT $pager->offset, $pageSize ") and while ($article->fetcharray ()) {$article- >data[' content ' = Mb_substr (strip_tags ($article->data[' content '), 0,40, ' utf-8 '); $articleIndex [] = $article- >data;} $article->free ();} else {header ("Location:?act=login");} $view->view->assign (' StartRow ', $startRow);//caption$view->view->assign (' Total ', $total);//caption$ View->view->assign (' Pagenums ', $pager->numpages ());//pagenums$view->view->assign (' NoncePage ', $ Pager->noncepage ());//pagenums$view->view->assign (' Pagetotal ', $pager->pagetotal);//pageTotal
Template page:
[PHP]
This article comes from "
Qingyuan Education"Blog, reproduced please specify here, thank you!"