search
HomeBackend DevelopmentPHP ProblemHow 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.

How to implement multi-condition fuzzy query in PHP

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(&#39;post.name&#39;);  
$mail = I(&#39;post.mail&#39;);  
$age = I(&#39;post.age&#39;);  
if(!empty($name)){  
                //封装模糊查询 赋值到数组 
$where[&#39;name&#39;] = array(&#39;like&#39;,&#39;%&#39;.$name.&#39;%&#39;); 
}  
if(!empty($mail)){  
$where[&#39;mail&#39;] = array(&#39;like&#39;,&#39;%&#39;.$mail.&#39;%&#39;);  
}  
if(!empty($age)){  
$where[&#39;age&#39;] = $age;  
} 
                //如果查询条件是OR的关系请打开,一般都是AND关系。 
$where[&#39;_logic&#39;]=&#39;OR&#39;;  
$test = M(&#39;table&#39;)->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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor