搜索后分页
来源:互联网 发布:猪湾事件知乎 编辑:程序博客网 时间:2024/05/23 01:20
搜索页面
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><script src="jq.js"></script></head><body><form action="?r=sp/search" method="post"><table border="1" align="center"><tr><td><input type="text" class="price" name="price"></td><td><input type="submit" value="搜索" class="search"></td></tr></table></form></body></html>控制器
class SpController extends Controller{public $enableCsrfValidation = false;public function actionLogin(){return $this->renderPartial('login');}public function actionSearch(){if(\Yii::$app->request->isPost){$price=\yii::$app->request->post('price');}else{$price=\yii::$app->request->get('price');}$db=new Page_search;$ac=$db->find()->where("username like '%$price%'")->count();//接受分页的值$page=\yii::$app->request->get('page');//判断分页是否存在$pages=isset($page)?$page:1;//设置每页显示条数$number=2;//设置总页数$num_page=ceil($ac/$number);//设置上下页$last=$pages-1<=1?$pages:$pages-1;$next=$pages+1>=$num_page?$num_page:$pages+1;//计算偏移量$offset=($pages-1)*$number;$where="username like '%$price%'";$sql="select * from page_search where $where limit $offset,$number";$list=$db->findBySql($sql)->asArray()->all();$p['last']=$last;$p['next']=$next;$p['num_page']=$num_page;$p['price']=$price;return $this->renderPartial('search',['list'=>$list,'page'=>$p]);}}搜索后展示页面
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><table border="center"><tr><td>姓名</td><td>电话</td><td>地址</td></tr><?php foreach ($list as $key => $v): ?><tr><td><?= $v['username']?></td><td><?= $v['userphone']?></td><td><?= $v['usersite']?></td></tr><?php endforeach ?><tr><td><a href="?r=sp/search&page=1&price=<?= $page['price']?>">首页</a></td><td><a href="?r=sp/search&page=<?= $page['last']?>&price=<?= $page['price']?>">上页</a></td><td><a href="?r=sp/search&page=<?= $page['next']?>&price=<?= $page['price']?>">下页</a></td><td><a href="?r=sp/search&page=<?= $page['num_page']?>&price=<?= $page['price']?>">尾页</a></td></tr></table></body></html>
0 0
- 搜索后分页
- 原生分页后搜索
- 搜索后分页
- 分页,搜索后保留搜索条件分页
- EXTjs 搜索后 实现分页
- laravel的搜索后分页
- yii框架搜索后分页
- 类似百度搜索后分页的实现
- laravel框架的搜索后分页
- yii框架搜索后分页查询方法
- lavarel5.2中多表联查 搜索后分页
- laravel 的 分页以及条件搜索后分页
- 实现“GridView搜索后,显示结果,分页后,仍然显示搜索后的结果”
- lavarel框架增 删 改 查 以及 分页 搜索(搜索后分页)
- 解决Gridview在搜索后,分页点击失效的解决办法
- Laravel 框架 ajax多条件搜索后 分页
- 分页+搜索
- jquery datatable 通过ajax从后台获取每个分页数据后,搜索框无法搜索问题
- .net学习
- Mysql笔记
- 使用一维数组模拟栈
- Android新布局-ConstraintLayout详解
- 用java写的打印日历小程序
- 搜索后分页
- 堆--建筑抢修nkoj2375
- mysql读写分离
- Spring 国际化支持 消息传递 以及 AOP 面向方面编程
- poj 2965 The Pilots Brothers' refrigerator
- 随堂笔记7.27:方法的组成,递归方法------2
- 走进Git的世界
- POJ 2184 Cow Exhibition 01背包
- 数据结构上机测试2-1:单链表操作A