我在CodeIgniter上查询的问题,我想在两个参数之间找到数据。比如下面的例子。
控制器
public function search_genus() {
$data = array(
'find_kebun' => $this->my_model->find(),
'content' =>'my_view'
);
$this->load->view('layout/wrapper', $data);
}
模型
public function find() {
$search = $this->input->post('param');
$A = "1 - 10";
$B = "11- 15";
if ($search = $A ) {
$query = $this->db->select('*')
->from('my_tables')
->where('genus', 1 > 10)
->get();
return $query->result();
}else if ($search = $B ) {
$query = $this->db->select('*')
->from('my_tables')
->where('genus', 11 > 15)
->get();
return $query->result();
}
}
浏览
<form action="<?php echo base_url(); ?>/search_genus" method="post" enctype="multipart/form-data">
<select name="param">
<option value="A">1 - 10</option>
<option value="B">11 - 15</option>
</select>
<button class="btn btn-default" type="submit">
</form>
我在哪里运行错误怎么解决?
答案 0 :(得分:1)
试试这个 - 控制器:
public function search_genus() {
$search = $this->input->post('param');
$data = array(
'find_kebun' => $this->my_model->find($search ),
'content' =>'my_view'
);
$this->load->view('layout/wrapper', $data);
}
和模型
public function find($search) {
$A = "1 - 10";
$B = "11- 15";
if ($search == "A" ) {
$query = $this->db->select('*')
->from('my_tables')
->where('genus', 1 > 10)
->get();
return $query->result();
}else if ($search == "B" ) {
$query = $this->db->select('*')
->from('my_tables')
->where('genus', 11 > 15)
->get();
return $query->result();
}