Home >Backend Development >PHP Tutorial >fleaphp A clever solution to uncertain multi-condition queries under fleaphp
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.