Paging program design understanding page. class. php

Source: Internet
Author: User
Paging program design understanding page. class. php about paging program, I understand that when a link such as [Next page] is clicked, the corresponding data on the next page is displayed.

This is essentially a database operation. Simply put, the SQL statement is the select some_fields from table limit Offset Num;

Here, Num is fixed. for example, 10 data entries are displayed on each page.

The key is Offset, that is, the Offset. this value changes every time you click the next page, for example, 10 ....

There are only two things finally displayed on the page. one is the corresponding data (images, text, etc ...), one is a paging link (xx records are displayed in total, 10 records are displayed on each page. Currently, page 1/32 [Homepage] [Previous Page] [Next Page] [last Page])

The specific implementation code below

 Count = $ count; $ this-> meiye = $ meiye; $ this-> pages = ceil ($ this-> count/$ this-> meiye ); $ this-> now_page = $ this-> get_now_page (); $ this-> url = $ url; $ this-> prev = $ this-> get_prev_page (); $ this-> next = $ this-> get_next_page (); $ this-> offset = $ this-> get_offset (); $ this-> style = $ this-> get_style ($ style);} // Obtain the current page private function get_now_page () {return isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;} // GET the previous page private function get_prev_page () {return $ this-> now_page-1? $ This-> now_page-1: false;} // get the next page private function get_next_page () {return $ this-> now_page + 1> $ this-> pages? False: $ this-> now_page + 1;} // Get the offset private function get_offset () {return $ this-> now_page <= 1 & $ this-> now_page> 0? 0 :( $ this-> now_page-1) * ($ this-> meiye);} // get paging link style default: // 30 records in total, 4 records per page, current page 1/8 [Homepage] [Next Page] [last Page] private function get_style ($ s) {$ str = ''; if ($ this-> pages> 1) {if ($ s = 1) {$ str. = "{$ this-> count} records in total, {$ this-> meiye} records per page, current page {$ this-> now_page}/{$ this-> pages} "; $ str. = "url? Page = 1'> [Homepage] "; $ this-> prev? $ Str. = "url? Page = $ this-> prev '> [previous page] ": false; $ this-> next? $ Str. = "url? Page = $ this-> next '> [next page] ": false; $ str. =" url? Page = $ this-> pages '> [last page] ";} else {$ str. = "current page {$ this-> now_page}/{$ this-> pages}"; $ str. = "url? Page = 1'> [Homepage] "; $ this-> prev? $ Str. = "url? Page = $ this-> prev '> [previous page] ": false; for ($ j = 1; $ j <= $ this-> pages; $ j ++) {$ str. = "url? Page = $ j> $ j ";}$ this-> next? $ Str. = "url? Page = $ this-> next '> [next page] ": false; $ str. =" url? Page = $ this-> pages '> [last page] ";}return $ str ;}}}

When used, get the Offset and style

 Acount (); // instantiate the paging class (total number of records, number of records displayed per page, execution script, style) $ p = new page ($ c, 4, 'page3. php ', 1); // Get the offset $ of = $ p-> offset; // query the database $ res = $ m-> select ('Pic ','', ''," $ of, 4 "); // convenient result set $ res // output paging link echo $ p-> style;

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.