ThinkPHP学习笔记(八)条件查询
2013-08-25 16:30
148 查看
一、建立项目与配置项目及数据库基本操作等内容:请参考《ThinkPHP学习笔记(一 ~ 七)》
二、查询模块实现:
效果图如下
1、首先在C层UserAction.class.php中添加public function search() {}方法
2、,并在V层添加查询表单:
这样就实现了搜索功能,打开http://localhost/ThPHP/index.php/User/ ,然后输入搜索条件,点击搜索,在User/index页面展示搜索结果($this->display('index');)
其他:order()、limit()
$arr=$m->order(arr('id'=>'desc','sex'=>'asc'))->limit(2,3)->select();按id降序,sex升序,第二个位置,去长度3的所有元素
二、查询模块实现:
效果图如下
1、首先在C层UserAction.class.php中添加public function search() {}方法
public function search() { $m=M('User'); if(isset($_POST['username']) && $_POST['username']!=null); { $where['username']=array('like',"%{$_POST['username']}%"); } if(isset($_POST['sex']) && $_POST['sex']!=null) { $where['sex']=array('eq',$_POST['sex']); } $arr=$m->where($where)->select(); $this->assign('data',$arr); $this->display('index');//在User/index页面展示搜索结果,不在重新增加一个search.html页面 }
2、,并在V层添加查询表单:
<html> <head> <title>Index</title> <script> function jump() { window.location="__URL__/add"; } </script> </head> <body> <form align='center' action='/ThPHP/index.php/User/search' method='post'> 用户名:<input type="text" name='username'/> 性别:<input type="radio" name='sex' value='1'>男 <input type="radio" name='sex' value='0'>女 <input type="submit" value='搜索'> </form> <table border='1' width='500' align='center'> <tr> <th>id</th> <th>username</th> <th>sex</th> <th>操作</th> </tr> <volist name='data' id='vo'> <tr> <td><{$vo.id}></td> <td><{$vo.username}></td> <td><{$vo.sex}></td> <td><a href="/ThPHP/index.php/User/del/id/<{$vo.id}>">删除</a> | <a href="/ThPHP/index.php/User/modify/id/<{$vo.id}>">修改</a></td> </tr> </volist> </table> <center> <button onclick="jump()">添加</button> </center> </body> </html>
这样就实现了搜索功能,打开http://localhost/ThPHP/index.php/User/ ,然后输入搜索条件,点击搜索,在User/index页面展示搜索结果($this->display('index');)
其他:order()、limit()
$arr=$m->order(arr('id'=>'desc','sex'=>'asc'))->limit(2,3)->select();按id降序,sex升序,第二个位置,去长度3的所有元素
相关文章推荐
- 实现Linq扩展,统一添加按租户过滤查询条件
- ASP多条件查询后翻页问题
- JDBC的多条件动态查询
- 当查询一个列表的时候获取此列表id结果作为另一个sql的是否存在的条件处理
- MySQL的时间条件查询
- lucene多条件查询
- 多字段查询,多条件查询写法
- Kibana 使用简介及查询条件示例
- EAS 在自动生成的查询中加自定义的条件
- ext4.0分页条件查询
- 06_Jedis完成MySQL的条件查询案例
- 在使用ibatis实现多条件模糊查询的语句
- 查询条件(规约模式应用)
- iBatis动态条件查询 where的if条件不执行
- Mondrian的schema中,如何做到同一纬度的不同level数据作为查询条件来用?
- MySQL种字符串拆分(substring_index)并作为关联查询条件后多列展示
- ExtJs 4分页(pagingtoolbar)带参数(条件)查询解决方法
- 指定查询条件,查询对应的集合List(单表)
- Sql Server根据表名生成查询的存储过程(查询条件可选)
- thinkphp5多条件模糊查询以及多条件查询带分页如何保留参数