layui的分页器
作者:互联网
<?php
$key = isset($_GET['key']) ? $_GET['key'] : '';
$page = isset($_GET['page']) ? $_GET['page'] : 1; $pnum = 3; $sqlnum = ($page - 1) * $pnum . ',' . $pnum; //查询数据 $conn = new mysqli('localhost', 'root', 'root', 'qiye'); $sql = "select * from product where title like '%$key%' limit $sqlnum"; $res = $conn->query($sql); // var_dump($res); $list = $res->fetch_all(MYSQLI_ASSOC); // 总条数 $sql = "select * from product where title like '%$key%'"; $zongnum = $conn->query($sql); $zongnum = $zongnum->num_rows; //总页码 $zpage = ceil($zongnum / $pnum); //向上取整 var_dump($zongnum);
//
$conn->close(); ?> <script> layui.use('laypage', function() { var laypage = layui.laypage;
//执行一个laypage实例 laypage.render({ elem: 'test1' //注意,这里的 test1 是 ID,不用加 # 号 , count: <?php echo $zongnum ?> //数据总数,从服务端得到 , limit: <?php echo $pnum; ?> //每页显示条数 , curr: <?php echo $page; ?> //当前页码 , jump: function(obj, first) { //首次不执行 if (!first) { location.href = 'liebiao.php?page=' + obj.curr + '&key=<?php echo $key ?>'; //中间一定不要有空格 } } }); }); </script>
$key = isset($_GET['key']) ? $_GET['key'] : '';
$page = isset($_GET['page']) ? $_GET['page'] : 1; $pnum = 3; $sqlnum = ($page - 1) * $pnum . ',' . $pnum; //查询数据 $conn = new mysqli('localhost', 'root', 'root', 'qiye'); $sql = "select * from product where title like '%$key%' limit $sqlnum"; $res = $conn->query($sql); // var_dump($res); $list = $res->fetch_all(MYSQLI_ASSOC); // 总条数 $sql = "select * from product where title like '%$key%'"; $zongnum = $conn->query($sql); $zongnum = $zongnum->num_rows; //总页码 $zpage = ceil($zongnum / $pnum); //向上取整 var_dump($zongnum);
//
$conn->close(); ?> <script> layui.use('laypage', function() { var laypage = layui.laypage;
//执行一个laypage实例 laypage.render({ elem: 'test1' //注意,这里的 test1 是 ID,不用加 # 号 , count: <?php echo $zongnum ?> //数据总数,从服务端得到 , limit: <?php echo $pnum; ?> //每页显示条数 , curr: <?php echo $page; ?> //当前页码 , jump: function(obj, first) { //首次不执行 if (!first) { location.href = 'liebiao.php?page=' + obj.curr + '&key=<?php echo $key ?>'; //中间一定不要有空格 } } }); }); </script>
标签:laypage,分页,GET,layui,zongnum,pnum,page,conn 来源: https://www.cnblogs.com/1171899qq/p/13073714.html