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

2022-09-11 09:16:26
	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://liaosp.blog.csdn.net/article/details/54288671
    更新时间:2022-09-11 09:16:26