public function user_list(){
//接收当前页面
$p = Request::instance()->param("page");
$page = empty($p)?1:$p;
//查询总条数
$count = Db::table("user")->count();
//设置每页显示的条数
$length = 2;
//求出总页数
$zong_page = ceil($count/$length);
//偏移量
$limit = ($page-1)*$length;
//查询
$data = Db::table("user")->limit($limit,$length)->select();
//赋值展示
$arr = ['list'=>$data,'last_page'=>$zong_page];
return view("user_list",['arr'=>$arr]);
}
echo json_encode($arr);
<tbody id="tb">
<input type="hidden" name="current_page" id="current_page" value="1">
<input type="hidden" name="last_page" id="last_page" value="{$arr.last_page}">
<a href="javascript:void(0)" class="pag">首页</a>
$(document).ready(function(){
$(".pag").click(function(){
var tag=$(this).text();
var shou=$("#shou").val();
var last=$("#last").val();
var p='';
//进行判断
if(tag=='首页'){
p=1;
}else if(tag=='上一页'){
p=parseInt(shou)-1<=1 ? 1 : parseInt(shou)-1;
}else if(tag=='下一页'){
p=parseInt(shou)+1>=last ? last : parseInt(shou)+1;
}else{
p=last;
}
$.get(
"{:url('node/user_lists_json')}?page="+p,
function (data) {
var res = JSON.parse(data);
//表单里面的数据
var table_data = res.list;
var str = '';
$.each(table_data,function (k,v) {
str += "<tr>";
str += "<td>"+v.uid+"</td>";
str += "<td><a href='#'>删除</a> <a href='#'>修改</a> </td>";
str += "</tr>";
});
//替换内容
$("#tb").html(str);
//改变当前页的值
$("#current_page").val(p);
}