2017-03-21 60 views
0

我在查詢的CodeIgniter的位置有問題,我想在兩個參數之間找到數據。如下面的例子。用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

@ thansk splash58,但我想顯示值1到10,而如果B =只是價值11〜15 –

回答

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();  
    }