Home > Backend Development > PHP Tutorial > fleaphp A clever solution to uncertain multi-condition queries under fleaphp

fleaphp A clever solution to uncertain multi-condition queries under fleaphp

WBOY
Release: 2016-07-29 08:38:49
Original
1088 people have browsed it

Question: For example, the implementation is as follows
$data = array(
'id' => $_POST['id1'],
'name' => $_POST['name1']
);
$posts = $this ->_modelstudent->findAll($data);
There is a text box with id name on the page. You can enter the ID query or NAME query or you can enter the query at the same time;
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]}";
}
}
}

The above introduces the ingenious solution to uncertain multi-condition queries under fleaphp, including fleaphp content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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