layui 分页的用法事例

layui 分页JS部分:

function fyppFun(){
    layui.use('table', function(){
          var table = layui.table;
          table.render({
            elem: '#demo'
            ,height:500
            ,url:'paipian.php?type=messege' //数据接口
            ,page: true //开启分页
            ,data:{limit:10}//每页显示10条数据
            ,cols: [[ //表头
              {field: 'id', title: 'ID', 200, sort: true, fixed: 'left'}
              ,{field: 'fytime', title: '放映时间', 200}
              ,{field: 'language', title: '语言版本', 200, sort: true}
              ,{field: 'video', title: '放映厅', 300}
            ,{field: 'price', title: '售价', 200}
            ,{field: 'people', title: '客容量', 200},
            {field: '', title: '操作', 500,templet:function(d){
                return `<button  class="layui-btn layui-btn-radius" update="`+d.id+`"                           onClick="threeaFun(this)" style="100px;">修改</button>
                        <button  class="layui-btn layui-btn-radius layui-btn-normal" insert="`+d.id+`"  onClick="threebFun(this)" style="100px;">添加</button>
                        <button  class="layui-btn layui-btn-radius layui-btn-danger" delect="`+d.id+`"  onClick="threecFun(this)" style="100px;">删除</button>`;
                      }},    
                ]]
              });
        });
    }

layui 分页PHP部分:

case'messege':
    //排片管理分页的后台语句
    $sql = "select count(*) from movie_messege";
    $res = $db->query($sql);
    $con = $res->fetch_row();
    $page = $_GET["page"];
    $limit = $_GET["limit"];
    $lit = ($page-1)*$limit.",".$limit;//数据分页
    /*接收空位*/
    $sql = "select * from movie_messege limit ".$lit;
    $res  = $db->query($sql);
    $rows = array();
    while($row=$res->fetch_assoc()){
      $rows[] = $row;
   }
     $arr = array(
      "code"=> 0,
       "msg"=> "",
       "count"=> $con[0],
       "data"=>$rows
        );
    echo json_encode($arr);

原文地址:https://www.cnblogs.com/Prinlily/p/9657305.html