Transformation of thinkphp Paging function

Source: Internet
Author: User
First after creating the Thinkphp project, open the root directory thinkphp/common/functions.php (here is the common function of TP)   Add the following code    
 1 function mypage ($tot, $length) {2 $page =$_get[' P ']?$_get[' P ';
 3 $offset = ($page-1) * $LENGTH;
 4 $prevpage = $page-1;
 5 6 $pages =ceil ($tot/$length);     7 8 if ($page >= $pages) {9 $nextpage = $pages;}else{$nextpage = $page +1; 12} 13 14
$limit = "{$offset},{$length}";          $show = "
This defines the paging function.   The Class A connection can be defined by itself or undefined, and then the HTML definition style of pagination is selected from the parent element in the page by CSS. Then you reference the paging function 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 ();
Referencing in TPL templates: 1 <div> 2 <{$show}> 3 </div> because I'm using bootstrap so the effect is as follows, styles can be defined by CSS

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.