Php paging code Problems

Source: Internet
Author: User
The following examples are not available on the Internet. Can you help me identify the problem? I wonder which table does this class query without database operations? {Code...} call method {code...} The following example found on the internet is actually unavailable. Can you help me identify the problem? I wonder which table does this class query without database operations?

Class Page {private $ total; // total record private $ pagesize; // The number of private $ limit entries displayed on each page; // limit private $ Page; // The current page number private $ pagenum; // The total page number private $ url; // The address private $ bothnum; // The number of remaining numeric pagination on both sides // constructor initializes 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;} // obtain 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 the 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-> page-$ 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 Page 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';} // the last page of the private function last () {if ($ this-> pagenum- $ This-> page> $ this-> bothnum) {return '... url. '& page = '. $ this-> pagenum. '"> '. $ this-> pagenum. '';} // public function showpage () {$ _ page. = $ this-> first (); $ _ page. = $ this-> pageList (); $ _ page. = $ this-> last (); $ _ page. = $ this-> prev (); $ _ page. = $ this-> next (); return $ _ page ;}}?>

Call Method


  

Reply content:

The following examples are not available on the Internet. Can you help me identify the problem? I wonder which table does this class query without database operations?

Class Page {private $ total; // total record private $ pagesize; // The number of private $ limit entries displayed on each page; // limit private $ Page; // The current page number private $ pagenum; // The total page number private $ url; // The address private $ bothnum; // The number of remaining numeric pagination on both sides // constructor initializes 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;} // obtain 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 the 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-> page-$ 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 Page 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';} // the last page of the private function last () {if ($ this-> pagenum- $ This-> page> $ this-> bothnum) {return '... url. '& page = '. $ this-> pagenum. '"> '. $ this-> pagenum. '';} // public function showpage () {$ _ page. = $ this-> first (); $ _ page. = $ this-> pageList (); $ _ page. = $ this-> last (); $ _ page. = $ this-> prev (); $ _ page. = $ this-> next (); return $ _ page ;}}?>

Call Method


  

The owner must understand the paging logic for database operations. Pages can be divided into two parts: the first part is the data, and the second part is the page number. When writing a program, we only need the client to pass us a parameter, that is, the current page number.
The code above actually helps you implement the second part. First, you can query the database to get the total number of entries and customize the number of entries displayed on each page. Then, use the current query page number sent from the client to write the SQL statement to obtain the data, that is, the first part.

It is possible that the returned path is encapsulated elsewhere through setUrl (). The subject can refer to this article: PHP paging: Text paging and digital paging.

Isn't it clearly written?
Construct parameter passing
Then, call showpage.

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.