Home > Article > Backend Development > Transformation of ThinkPHP paging function_PHP tutorial
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 <h4> 18 <a href='__SELF__/p/1'class='btn btn-warning btn-sm'>首页</a> 19 <a href='__SELF__/p/{$prevpage}' class='btn btn-warning btn-sm'>上一页</a> 20 <span>{$page}/{$pages}</span> 21 <a href='__SELF__/p/{$nextpage}' class='btn btn-warning btn-sm'>下一页</a> 22 <a href='__SELF__/p/{$pages}' class='btn btn-warning btn-sm'>末页</a> 23 </h4>"; 24 C('limit',$limit); 25 C('show',$show); 26 }
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();
http://www.bkjia.com/PHPjc/1047179.html