分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

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

发布时间:2023-09-06 02:14责任编辑:傅花花关键词:jQuery

html代码:

<!DOCTYPE html><html><head> ???<meta charset="utf-8"> ???<title></title></head><body> ???<input type="text" id="word" value="{$data.word}"> ???<input type="button" value="搜索" onclick="page(1)"><table> ???<tr> ???????<th>ID</th> ???????<th>账号</th> ???????<th>密码</th> ???????<th>手机</th> ???????<th>登录时间</th> ???????<th>登录次数</th> ???????<th>状态</th> ???</tr> ???{volist name="data.list" id="v"} ???<tr> ???????<td>{$v.id}</td> ???????<td>{$v.uname}</td> ???????<td>{$v.pwd}</td> ???????<td>{$v.phone}</td> ???????<td>{$v.login_time|date="Y-m-d H:i:s",###}</td> ???????<td>{$v.login_num}</td> ???????<td> ???????????{switch name="$v.is_on" } ???????????????{case value="1"}正常{/case} ???????????????{case value="2"}锁定{/case} ???????????{/switch} ???????</td> ???</tr> ???{/volist}</table><a href="javascript:void(0);" onclick="page({$data.home_page})">首页</a><a href="javascript:void(0);" onclick="page({$data.prev_page})">上一页</a><a href="javascript:void(0);" onclick="page({$data.next_page})">下一页</a><a href="javascript:void(0);" onclick="page({$data.last_page})">尾页</a><script src="__STATIC__/js/jquery.js"></script><script> ???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); ???????????}) ???????} ???????????}</script></body></html>

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页面替换+php代码实现搜索后分页

原文地址:https://www.cnblogs.com/hopelooking/p/9639656.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved