The following examples are found online and are not actually available. Please help to point out the problem? I wonder if this class does not need to manipulate the database and query which table?
Class Page {private $total; Total Records private $pagesize; How many private $limit are displayed per page; Limit private $page; Current page number private $pagenum; Total page number private $url; Address private $bothnum; The amount of number paging on both sides//construction Method Initialize Public function __construct ($_total, $_pagesize) {$this->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; }//Gets 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 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 directory Private Function PageList () {for ($i = $this->bothnum; $i >=1; $i-) {$_page = $this->pa ge-$i; if ($_page < 1) continue; $_pagelist. = ' URL. ' &page= '. $_page. ' " > '. $_page. ' '; } $_pagelist. = ''. $this->page. ''; for ($i =1; $i <= $this->bothnum; $i + +) {$_page = $this->page+ $i; 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 ... '; }}//prev Private Function prev () {if ($this->page = = 1) {return 'Previous Page'; } return ' URL. ' &page= '. ($this->page-1). ' " > previous page '; }//Next Private Function next () {if ($this->page = = $this->pagenum) {return 'Next Page'; } return ' URL. ' &page= '. ($this->page+1). ' " > next page '; }//End 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; }}?>
Invocation mode
Reply content:
The following examples are found online and are not actually available. Please help to point out the problem? I wonder if this class does not need to manipulate the database and query which table?
Class Page {private $total; Total Records private $pagesize; How many private $limit are displayed per page; Limit private $page; Current page number private $pagenum; Total page number private $url; Address private $bothnum; The amount of number paging on both sides//construction Method Initialize Public function __construct ($_total, $_pagesize) {$this->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; }//Gets 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 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 directory Private Function PageList () {for ($i = $this->bothnum; $i >=1; $i-) {$_page = $this->pa ge-$i; if ($_page < 1) continue; $_pagelist. = ' URL. ' &page= '. $_page. ' " > '. $_page. ' '; } $_pagelist. = ''. $this->page. ''; for ($i =1; $i <= $this->bothnum; $i + +) {$_page = $this->page+ $i; 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 ... '; }}//prev Private Function prev () {if ($this->page = = 1) {return 'Previous Page'; } return ' URL. ' &page= '. ($this->page-1). ' " > previous page '; }//Next Private Function next () {if ($this->page = = $this->pagenum) {return 'Next Page'; } return ' URL. ' &page= '. ($this->page+1). ' " > next page '; }//End 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; }}?>
Invocation mode
Why need to operate the database, landlord to understand the logic of paging. Pagination can be divided into two parts, the first part is the data, the second part is the page number bar. When we write the program, we only need the client to send us a parameter, and that is the current page number.
The above code actually helps you achieve the second part, you first through the database to get the total number and customize a display number per page you can use this class to get the page number bar. Then through the client's current query page to write SQL to get data, that is, the first part.
It is possible that the return path through SetUrl () has been encapsulated somewhere else, the main topic can look at this: PHP implementation paging: Text paging and digital paging
It's not written very clearly.
Construct a parameter
Then call ShowPage