How to use a written class?

Source: Internet
Author: User
I did not write this paging class on the Internet, but I don't know how to use it? I can see that there is only one such class in this class. No example. I am a newbie, but I can understand it. It is only in this class that I have never touched on object-oriented connection classes before ... I did not write this paging class on the Internet, but I don't know how to use it? I can see that there is only one such class in this class. No example. I am a newbie. I can understand it. I just understand it in this class. I have never touched on object-oriented connection classes in practice. I don't know how to use this class to pass two parameters to the constructor, for example, to connect to the database. Why didn't I connect to the database? Where should I write them?


  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;} // homepage 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 priva Te 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 ;}}?>

Reply content:

I did not write this paging class on the Internet, but I don't know how to use it? I can see that there is only one such class in this class. No example. I am a newbie. I can understand it. I just understand it in this class. I have never touched on object-oriented connection classes in practice. I don't know how to use this class to pass two parameters to the constructor, for example, to connect to the database. Why didn't I connect to the database? Where should I write them?


  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;} // homepage 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 priva Te 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 ;}}?>

It is just a paging class. You can think of it as just that simple to give an array pagination. It would be too complicated to couple the database.

You can use include directly.

First, this class contains some methods and attributes, which are used to "pagination" and be used after instantiation.
In addition, the main function of the so-called "Paging class" is to calculate the limit in a query SQL statement and then calculate the number of pages to be displayed. It is very easy to take a closer look at the several methods to understand.
In the end, this thing is more than a decade or eight years old. If you want to learn new things, don't worry about these things. From the new beginning, learn more about the basics. You can refer to php: the right way is also called the "php path" or something. keep up with the times. Haha

I wrote some text on the phone, hoping it would be helpful.

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.