fleaphp下不确定的多条件查询的巧妙解决方法
问题:例如,实现如下
$data = array(
'id' => $_POST['id1'],
'name' => $_POST['name1']
);
$posts = $this->_modelstudent->findAll($data);
页面上有 id name 的文本框 可输入ID查询 也可输入NAME查询 也可同时输入查询 ;
解决:写循环做判断
例子如下:
$conditions = null;
$fields = array('id', 'name', 'sex', 'phone');
foreach($fields as $each) {
if(!empty($_POST[$each])) {
if($conditions) {
$conditions .= " AND {$each}={$_POST[$each]}";
} else {
$conditions .= "{$each}={$_POST[$each]}";
}
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools