Useful PHP Paging class code and use

Source: Internet
Author: User
Useful PHP Page class code and use

The code for the class is as follows:

 Total = $_total? $_total:1;??? $this->pagesize = $_pagesize;?? $this->pagenum = ceil ($this->total/$this->pagesize);??? $this->page = $this->setpage ();??? $this->limit = "Limit". ($this->page-1) * $this->pagesize. ", $this->pagesize";??? $this->url = $this->seturl ();??? $this->bothnum = 2;??}???? Interceptor?? Private Function __get ($_key) {??? return $this->$_key;??}???? Get the current page number?? Private Function Setpage () {??? if (!empty ($_get[' page ')) {???? if ($_get[' page '] > 0) {????? if ($_get[' page '] > $this->pagenum) {?????? return $this->pagenum;?????} else {?????? Return $_get[' page '];?????}????} else {????? return 1;????}???} else {???? return 1;???}??}????? Get an address?? Private Function SetUrl () {??? $_url = $_server["Request_uri"];??? $_par = Parse_url ($_url);??? if (isset ($_par[' query ')) {???? PARSE_STR ($_par[' query '],$_query);???? unset ($_query[' page ');???? $_url = $_par[' path ']. '? '. Http_build_query ($_query);???}??? return $_url;??}?? Digital catalogue?? Private Function PagelisT () {??? for ($i = $this->bothnum; $i >=1; $i-) {???? $_page = $i of $this->page-;???? if ($_page < 1) continue;???? $_pagelist. = ' URL. ' &page= '. $_page. ' " > '. $_page. ' ';???}???  $_pagelist. = ''. $this->page. '';??? for ($i =1; $i <= $this->bothnum; $i + +) {???? $_page = $i of $this->page+;???? if ($_page > $this->pagenum) break;???? $_pagelist. = ' URL. ' &page= '. $_page. ' " > '. $_page. ' ';???}??? return $_pagelist;??}???? Home http://ini.iteye.com/??private function First () {??? if ($this->page > $this->bothnum+1) {???? Return ' URL. ' " >1. ';???}??}???? Previous page?? Private Function prev () {??? if ($this->page = = 1) {???? Return 'Previous Page';???}??? Return ' URL. ' &page= '. ($this->page-1). ' " > previous page ';??}???? Next page?? Private function Next () {??? if ($this->page = = $this->pagenum) {???? Return 'Next Page';???}??? Return ' URL. ' &page= '. ($this->page+1). ' " > next page ';??}???? Last?? Private Function Last () {??? if ($this->pagenum-$this->page > $this->bothnum) {???? Return ' ... URL. ' &page= '. $this->pagenum. ' " > '. $this->pagenum. ' ';???}??}???? Paging information?? Public Function showpage () {??? $_page. = $this->first ();??? $_page. = $this->pagelist ();??? $_page. = $this->last ();??? $_page. = $this->prev ();??? $_page. = $this->next ();??? return $_page;??}?}? >

? ? Instructions for use:

 
  

? The paging style looks like this:?



?

  • 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.