Home > Backend Development > PHP Tutorial > Clever solution to uncertain multi-condition query under fleaphp_PHP tutorial

Clever solution to uncertain multi-condition query under fleaphp_PHP tutorial

WBOY
Release: 2016-07-21 15:50:16
Original
990 people have browsed it

Question: For example, the implementation is as follows:
$data = array(
'id' => );
$posts = $this->_modelstudent->findAll($data);
There is a text box with id name on the page, where you can enter the ID query, NAME query, or both;

Solution: Write a loop to make judgments
The example is as follows:
$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]}";
}
}
}

http://www.bkjia.com/PHPjc/319389.html

truehttp: //www.bkjia.com/PHPjc/319389.htmlTechArticleQuestion: For example, implement the following $data = array( 'id' = $_POST['id1'], ' name' = $_POST['name1'] ); $posts = $this-_modelstudent-findAll($data); There is a text box with id name on the page for input...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template