标签:
查询操作
Action模块 User下的search
1 public function search(){ 2 //判断username是否已经传入,且不为空 3 if(isset($_POST[‘username‘])&&$_POST[‘username‘]!=null){ 4 //不管{是出现在$前面还是后面,只有两者紧挨着时花括号才会被当成是界定符号。不要在之间加空格,要不然就会被当作普通的花括号处理 5 $where[‘username‘]=array(‘like‘,"%{$_POST[‘username‘]}%"); 6 } 7 if(isset($_POST[‘sex‘])&&$_POST[‘sex‘]!=null){ 8 $where[‘sex‘]=array(‘eq‘,$_POST[‘sex‘]); 9 } 10 $m=M(‘User‘); 11 //类似SELECT * FROM `tp_user` WHERE ( `username` LIKE ‘%李%‘ ) AND ( `sex` = ‘0‘ ) 12 $data=$m->where($where)->select(); 13 if($data==null){ 14 $this->error("没有查询到结果!",‘index‘); 15 } 16 else{ 17 $this->assign(‘data‘,$data); 18 $this->display(‘index‘); 19 } 20 }
User对应的index.html模板
1 <div style="width:400px;margin:0 auto;"> 2 <form action="__URL__/search" method="post"> 3 姓名:<input type="text" name="username" />性别:<input type="radio" name="sex" value="1" />男<input type="radio" name="sex" value="0" />女 4 <input type="submit" value="查询" /> 5 6 </form> 7 8 <table border=‘1‘ width=‘400px‘ align=‘center‘> 9 <tr> 10 <th>Id</th> 11 <th>User</th> 12 <th>sex</th> 13 <th>操作</th> 14 </tr> 15 <volist name=‘data‘ id=‘vo‘> 16 <tr> 17 <td><{$vo.id}></td> 18 <td><{$vo.username}></td> 19 <td><{$vo.sex}></td> 20 <td><a href=‘/thinkphp/test/index.php/User/del/id/<{$vo.id}>‘>删除</a>|<a href=‘/thinkphp/test/index.php/User/modify/id/<{$vo.id}>‘>修改</a></td> 21 </tr> 22 23 </volist> 24 </table> 25 <input type="button" value="添加" onclick="jump()"/> 26 </div>
标签:
原文地址:http://www.cnblogs.com/freestyle-le/p/4506241.html