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:
1
2 <{$ show}>
3
Because I use bootstrap, the effect is as follows. styles can be defined by css.
The transformation of the http://www.bkjia.com/PHPjc/1047179.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1047179.htmlTechArticleThinkPHP 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...