Home > Article > Backend Development > How to implement multi-condition fuzzy query in PHP
php method to implement multi-condition fuzzy query: first receive the post value; then pass "if(!empty($name)){$where['name'] = array('like','% '.$name.'%')..." method encapsulates the fuzzy query and assigns it to an array.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
PHP Fuzzy Query (Multiple Conditions)
The code is as follows:
//<!--php模糊查询 --> //接收post传值 $name = I('post.name'); $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; } //如果查询条件是OR的关系请打开,一般都是AND关系。 $where['_logic']='OR'; $test = M('table')->where($where)->select();
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to implement multi-condition fuzzy query in PHP. For more information, please follow other related articles on the PHP Chinese website!