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

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

WBOY
WBOYOriginal
2016-07-29 08:38:491056browse

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.

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