基本上,该代码通过拉取用户在表单中输入的数据并连接到基于输入信息执行查询搜索的模型。Codeigniter - 具有多个参数的搜索表单
此代码有效,但只有当我输入$ 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; ?>
检查天气这两个变量都不是空的,然后做相应的查询或更改查询 – vodich