Query operations
Search under the Action module user
1 Public functionsearch () {2 //determine if the username has been passed in and is not empty3 if(isset($_post[' username ']) &&$_post[' username ']!=NULL){4 //regardless of whether {it appears before or after, only the curly braces will be considered as a delimiting symbol when they are next to each other. Do not add spaces between them, otherwise they will be treated as ordinary curly braces.5 $where[' username ']=Array(' Like ', "%{$_post[' Username ']} %"); 6 }7 if(isset($_post[' Sex ']) &&$_post[' Sex ']!=NULL){8 $where[' Sex ']=Array(' eq ',$_post[' Sex ']);9 }Ten $m=m (' User '); One //similar to select * from ' Tp_user ' WHERE (' username ' like '% Li ') and (' sex ' = ' 0 ') A $data=$m->where ($where),Select (); - if($data==NULL){ - $this->error ("No query to results!") ", ' Index '); the } - Else{ - $this->assign (' Data ',$data); - $this->display (' Index '); + } -}
User-corresponding index.html template
1<div style= "width:400px;margin:0 auto;" >2<form action= "__url__/search" method= "POST" >3Name: <input type= "text" name= "username"/> Sex: <input type= "Radio" name= "Sex" value= "1"/> male <input type= " Radio "name=" Sex "value=" 0 "/>female4<input type= "Submit" value= "Query"/>5 6</form>7 8<table border= ' 1 ' width= ' 400px ' align= ' center ' >9<tr>Ten<th>Id</th> One<th>User</th> A<th>sex</th> -<th> Operations </th> -</tr> the<volist name= ' data ' id= ' VO ' > -<tr> -<td><{$vo.id}></td> -<td><{$vo.username}></td> +<td><{$vo.sex}></td> -<td><a href= '/thinkphp/test/index.php/user/del/id/<{$vo .id}> ' > Delete </a>|<a href= '/ thinkphp/test/index.php/user/modify/id/<{$vo .id}> ' > Modify </a></td> +</tr> A at</volist> -</table> -<input type= "button" value= "Add" onclick= "jump ()"/> -</div>
Thinkphp Study 10