"Code" PHP page type

Source: Internet
Author: User
"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!"

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.