thinkphp怎么做模糊查询搜索,完整实例,笨办法

$name = I('post.name');//接收post传值
$mail = I('post.mail');
$age = I('post.age');
if(!empty($name)){
$where['name'] = array('like','%'.$name.'%');//封装模糊查询 赋值到数组
}
if(!empty($mail)){
$where['mail'] = array('like','%'.'$mail'.'%');
}
if(!empty($age)){
$where['age'] = $age;
}
//$where['_logic']='OR';如果查询条件是OR的关系请打开,一般都是AND关系。
$test = M('table')->where($where)->select();
//回传查询条件:age到搜索条件;$this->assign('age',$age);
 
  


 
  
 
 

你可能感兴趣的:(php)