ThinkPHP paging function transformation _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP paging function transformation. ThinkPHP paging function transformation first after the ThinkPHP project is created, open ThinkPHPCommonfunctions. php under the root directory (which stores the tp public function) and add the following code 1 ThinkPHP paging function transformation
First, after creating the ThinkPHP project, open ThinkPHP/Common/functions. php in the root directory (the tp public function is stored here)

Add the following code:

1 function mypage ($ tot, $ length) {2 $ page = $ _ GET ['P']? $ _ GET ['P']: 1; 3 $ offset = ($ page-1) * $ length; 4 $ prevpage = $ page-1; 5 6 $ pages = ceil ($ tot/$ length); 7 8 if ($ page >=$ pages) {9 $ nextpage = $ pages; 10} else {11 $ nextpage = $ page + 1; 12} 13 14 $ limit = "{$ offset}, {$ length }"; 15 16 $ show = "17 18 homepage 19 previous 20 {$ page}/{$ pages} 21 next 22 Last 23"; 24 C ('limit', $ limit ); 25 C ('show', $ show); 26}

In this way, the paging function is defined. The class connected by a can be defined by itself or not, and then the html style of the page is selected from the parent element through css on the page.

The paging function is referenced in the Action: (the red part is the key code)

1         $goods=M('Goods');2         $count=$goods->where('is_pass=1 and is_self=1')->count();3         mypage($count,5);4         $this->rows=$goods->where('is_pass=1 and is_self=1')->limit(C('limit'))->order('trade_num desc,price asc')->select();5         $this->assign('show',C('show'));6         $this->display();

Reference in the tpl template:


2 <{$ show}>


Because I use bootstrap, the effect is as follows. styles can be defined by css.

The transformation of the paging function first after the ThinkPHP project is created, open ThinkPHP/Common/functions under the root directory. add the following code in php (which stores the tp public functions): 1...

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: 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.