layui 分页的用法事例

layui 分页JS部分:

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

layui 分页PHP部分:

//连接数据库
$db = new MySQLi("localhost","root","","z_0705");
!mysqli_connect_error() or die("数据库连接错误");
$db->query("set names utf8");

//分页的后台语句
$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";
$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);

猜你喜欢

转载自www.cnblogs.com/Prinlily/p/9657305.html
今日推荐