问题:例如,实现如下 $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]}"; } } }
申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
|