回顾tp5页面替换的方式进行分页
php代码
public function show2(){ //接收当前页 $page = input("get.page"); $cpage = empty($page) ? 1 : $page; //每页显示的条数 $length = 3; //总条数 $count = model('article')->getCount(); //总页数 $num_page = ceil($count/$length); //偏移量 $limit = ($cpage-1)*$length; //chaxun $data = model('article')->getAll($limit,$length); //判断 $arr['home'] = 1; $arr['prev'] = $cpage-1 <= 1 ? 1 : $cpage-1; $arr['next'] = $cpage+1 >= $num_page ? $num_page : $cpage+1; $arr['last'] = $num_page; $arr['data'] = $data; return view('show2',['arr'=>$arr]); }
html代码:
<table border="1"> <tr> <th>主键</th> <th>标题</th> <th>描述</th> </tr> {volist name="arr.data" id="v"} <tr> <td>{$v.id}</td> <td>{$v.title}</td> <td>{$v.desc}</td> </tr> {/volist} </table> <a href="javascript:void(0)" onclick="page({$arr.home})">首页</a> <a href="javascript:void(0)" onclick="page({$arr.prev})">上一页</a> <a href="javascript:void(0)" onclick="page({$arr.next})">下一页</a> <a href="javascript:void(0)" onclick="page({$arr.last})">尾页</a> <script src="__STATIC__/js/jquery-3.3.1.min.js"></script> <script> function page(obj) { $.get("{:url('Test/show2')}?page="+obj,function (data) { $("body").html(data); }) } </script>
通往牛逼的路上,在意的只有远方!