php 页面搜索 替换,jQuery页面替换+php代码实现搜索后分页

HTML代码

ID账号密码手机登录时间登录次数状态

{volist name="data.list" id="v"}

{$v.id}{$v.uname}{$v.pwd}{$v.phone}{$v.login_time|date="Y-m-d H:i:s",###}{$v.login_num}

{switch name="$v.is_on" }

{case value="1"}正常{/case}

{case value="2"}锁定{/case}

{/switch}

{/volist}

首页

上一页

下一页

尾页

function page(obj){

//获取搜索框的值

var word = $("#word").val();

if(word==''){

$.get("{:url('Three/home')}?page="+obj,function(data){

$("body").html(data);

})

}else{

//有值

$.get("{:url('Three/home')}?page="+obj+"&word="+word,function(data){

$("body").html(data);

})

}

}

PHP代码

//展示页面

public function home(){

//接收关键字

$word = Request::instance()->param('word');

if(empty($word)){

//查询所有的数据

//求出总条数

$count = Db::table("user")->count();

//设置每页显示的条数

$length = 2;

//求出来总页数

$zong_page = ceil($count/$length);

//接收当前页

$page = Request::instance()->param('page');

$current_page = empty($page) ? 1 : $page;

//求出偏移量

$limit = ($current_page-1)*$length;

//查询

$data = Db::table("user")->limit($limit,$length)->select();

}else{

//根据关键字实现多条件查询

//求出总条数(满足条件的)

$count = Db::table("user")->where('uname|phone','like',"$word%")->count();

//设置每页显示的条数

$length = 2;

//求出来总页数

$zong_page = ceil($count/$length);

//接收当前页

$page = Request::instance()->param('page');

$current_page = empty($page) ? 1 : $page;

//求出偏移量

$limit = ($current_page-1)*$length;

//查询

$data = Db::table("user")->where('uname|phone','like',"$word%")->limit($limit,$length)->select();

}

//判断页码

$arr['list'] = $data;

$arr['home_page'] = 1;

$arr['prev_page'] = $current_page-1 <= 1 ? 1 : $current_page-1;

$arr['next_page'] = $current_page+1 >= $zong_page ? $zong_page : $current_page+1;

$arr['last_page'] = $zong_page;

$arr['word'] = empty($word) ? null : $word;

return view('home',['data'=>$arr]);

}

标签:jQuery,arr,word,current,length,php,data,page,页面

来源: https://www.cnblogs.com/wxy0126/p/10615463.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值