查询方式实例演示
2016-07-06 23:48
288 查看
User模块的方法; public function search(){ var_dump($_POST); } <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus?"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> <script> function jump(){ window.location="http://localhost:8080/thinkphp/index.php/User/add"; } </script> </head> <body> <form action='/thinkphp/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> <h1>scan show 你好 hhhello world</h1> <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="http://localhost:8080/thinkphp/index.php/User/del/id/<{$vo.id}>">删除</a>|<a href="http://localhost:8080/thinkphp/index.php/User/modify/id/<{$vo.id}>">修改</a></td> </tr> </volist> </table> <center> <button onclick="jump()">添加用户</button> </center> </body> </html> <form action='/thinkphp/index.php/User/search' method='post'> form表单的动作是 调用/thinkphp/index.php/User/search public function search(){ var_dump($_POST); } 打印出的内容: array (size=2) 'username' => string 'xxyy' (length=4) 'sex' => string '1' (length=1) public function search(){ var_dump($_POST); // 获取POSTT的数据,根据数据组查询的条件,根据条件从数据库中获取数, //返回给页面遍历 把数据分配给前台模板,去找index的前台模板 $m=M('user'); if $where['username']=$_POST['username'] $where['sex']=$_POST['sex'] $arr=$m->where($where)->select() $this->assign('data',$arr); $this->display('index'); } 组装的SQL: SELECT * FROM `user` WHERE ( `username` = 'xxyy' ) AND ( `sex` = '0' ) [ RunTime:0.015743s ] $m=M('user'); if (isset($_POST['username'])){ $where['username']=$_POST['username']; }; if (isset($_POST['sex'])){ $where['sex']=$_POST['sex']; }; #$where['logic'] echo $where['username']; echo $where['sex']; $arr=$m->where($where)->select(); $this->assign('data',$arr); $this->display('index'); } $m=M('user'); if (isset($_POST['username']) && $_POST['username'] !=null ){ $where['username']=$_POST['username']; }; if (isset($_POST['sex']) && $_POST['sex'] !=null){ $where['sex']=$_POST['sex']; }; #$where['logic'] echo $where['username']; echo $where['sex']; $arr=$m->where($where)->select(); $this->assign('data',$arr); $this->display('index'); } 等价于; <form action='/thinkphp/index.php/User/search' method='post'> <form action='__URL__/search' method='post'>
相关文章推荐
- pickle.load报错
- Mongodb 和 spring的整合开发 权限认证 mongotemplate的group mapReduce开发
- Centos+nginx+tomcat 集群
- 认识B/S架构
- SQL CLR 储存过程与函数
- 查询方式实例演示
- 查询方式实例演示
- 原理-关联FP Growth算法
- [转载]EasyDarwin开源流媒体服务器内存管理优化
- 爬虫数据采集技术趋势-智能化解析
- 专题四--1003
- iOS-解决自定义cell.selectedBackgroundView 遮挡分割线问题
- 专题四--1003
- Microsoft Visual Studio 2015项目创建失败 解决办法
- POJ 1664 整数划分问题
- 经典错误“Error configuring application listener of class org.springframework.web.contex”的终极分析
- ANR完全解析
- 排序
- 2016SDAU课程练习四1023 Problem W
- LeetCode 70