thinkphp怎么like模糊查询数据库的信息curd操作

    xiaoxiao2021-03-26  8

    function index(){ //创建模型 $user=D('user'); $keywords=$_POST['keywords']; $type=$_POST['type']; if(!empty($keywords) && !empty($type)){ $where=$type." like '%".$keywords."%'"; }else{ } dump($where); $list=$user->where($where)->select(); $this->assign('ulist',$list); $this->display(); }

      

    view  代码:

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1 style="text-align: center;">查询数据</h1> <form action="__URL__/index" method="post"> 关键词:<input type="text" name="keywords" /> 类型:<select name="type"> <option value="username">用户名</option> <option value="name">昵称</option> <option value="id">id</option> </select> <input type="submit"value="查询" /> </form> <table border="10" bordercolor="red" width="30%" style="text-align: center;margin: auto;"> <tr><th>用户名</th><th>昵称</th><th>是否激活</th><th>ID</th></tr> <volist name="ulist" id="user"> <tr> <td>{$user['username']}</td> <td>{$user['name']}</td> <td>{$user['active']}</td> <td>{$user['id']}</td> </tr> </volist> <a href="__URL__/add">back</a> </table> </body> </html>

     that's all  thank you!

    转载请注明原文地址: https://ju.6miu.com/read-500029.html

    最新回复(0)