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