Thinkphp implementation page-PHP source code

Source: Internet
Author: User
Thinkphp implements paging php code

// Method for generating paging // obj is the instantiated object of the paging table, and limit is the number of items displayed on the left and right of the current page. // $ Map is the where condition for paging. // $ This-> size is a variable in my own class. Public function CreatePage ($ obj, $ limit, $ map = '') {// total number of items $ totalRows = $ obj-> where ($ map) -> count (); // The total number of pages $ totalPage = (round ($ totalRows/$ limit, 0); // The current page. $ NowPage = I ('Get. P ')? I ('Get. p '): 1; if ($ nowPage> $ this-> size) {$ start = $ nowPage-$ this-> size;} else {$ start = 1 ;} if ($ totalPage> ($ nowPage + $ this-> size) {$ end = $ nowPage + $ this-> size;} else {$ end = $ totalPage ;} if ($ nowPage ==$ totalPage) {$ start = $ nowPage-$ this-> size; $ end = $ totalPage;} $ page ['totalrows '] = $ totalRows; $ page ['totalpage'] = $ totalPage; $ page ['nowpage'] = $ nowPage; $ page ['start'] = $ start; $ page ['end'] = $ end; return $ page ;// Return to the call .. Assign values.

Front-end display page

 
 
  

Previous Page {$ I} {$ I} Next page Script var url = "{: Q ('P', ($ page ['nowpage'] + 1 ))}"; var nowpage = "{$ page ['nowpage']}"; var totalPage = "{$ page ['totalpage']}"; jump to script

Call

$ Page = $ this-> CreatePage ($ this-> obj, $ this-> size, $ map); // this is the query operation of TP. $ Data = $ this-> obj-> where ($ map)-> field ('Del, sequence, channel', true) // focus on this. $ Page ['nowpage'] page number. // $ This-> size-> page ($ page ['nowpage'], $ this-> size)-> order ('Sequence ') -> select ()

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.