• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
车车大人
博客园    首页    新随笔    联系   管理     

回顾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>

 

通往牛逼的路上,在意的只有远方!
posted @ 2019-07-06 10:58  车车大人  阅读(186)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3