基本上,此代码通过提取用户在表单中输入的数据来发挥作用,并连接到模型,该模型根据输入的信息执行查询搜索。
此代码有效,但仅当我同时输入 $no 和 $first 字段时才有效。但我需要它工作,这样用户才能输入 $no 并将其他变量留空。
我以为我可以使用某种 OR 语句,但我不确定如何实现它。任何帮助将不胜感激,如果它不够清楚,我对codeigniter还很陌生,我深表歉意。
控制器
public function query()
{
$no = $this->input->post('no');
$first = $this->input->post('first');
$this->load->model("test");
$data['query']=$this->test->query($no,$first);
$this->load->view('query',$data);
}
模型
function query($no, $first)
{
return $query = $this->db->get_where('table', array('no' => $no,
'first' => $first ))->result();
}
看法
<?php foreach($query as $row): ?>
<tr>
<td><?php echo $row->no; ?></td>
<td><?php echo $row->date; ?></td>
<td><?php echo $row->first; ?></td>
</tr>
<?php endforeach; ?>