2015-09-25 53 views
0

我想在last_name的情況下包含like子句。這是我的控制器代碼用於搜索box.I想比較窗體值last_name與db值family_name。like聲明在codeigniter

public function filtered_volunteer_details() 
{ 
    $user_data = $this->session->userdata("logged_user"); 
    $tab_result = array(); 
    if (is_array($user_data) && $user_data["user_role"] == "staff") 
    { 
     if ($this->input->method() == "post") 
     { 
      $condition = array(); 
      $data = $this->input->post(); 
      if(isset($data["membership_number"]) && $data["membership_number"]!= "") 
      { 
       $condition["membership_number"]=trim($data["membership_number"]); 
      } 
      if(isset($data["last_name"]) && $data["last_name"]!= "") 
      { 
       $condition["family_name "]=trim($data["last_name"]); 
      } 

      $this->load->model(array(
       "Users")); 
      $result = $this->Users->get_volunteers("*",$condition); 
      $volunteer_tbl_list=array(); 
      foreach($result as $volunteer_results) 
      { 
      $volunteer_tbl_list[] = $this->load->view("staff/manage_volunteer/volunteer_list_tbl_row", $volunteer_results, TRUE); 
      } 
      echo json_encode(array(
      "status" => "success", 
      "volunteer_tbl_list" => $volunteer_tbl_list)); 
      return; 
     } 
    } 

    echo json_encode(array(
     "error" => "true", 
     "msg" => "Invalid Access.")); 
    return; 
} 

這是我的模型代碼

public function get_volunteers($fields = "*",$condition=array()) 
{ 
    $condition["staff"]="N"; 
    $this->db->select($fields); 
    $query = $this->db->get_where(self::$tbl_name, $condition); 
    //var_dump($this->db->last_query()); 
    return($query->result()); 
} 
+0

你可以發佈ypur模型代碼嗎? – Saty

+0

你可以添加模型代碼嗎? –

回答

0

嘗試get_volunteers()添加$this->db->like()到查詢。 documentation

public function get_volunteers($fields = "*",$condition=array()) 
{ 
    $condition["staff"]="N"; 
    $this->db->select($fields); 
    $this->db->like($condition); 
    $this->db->from(self::$tbl_name); 
    return($query->result()); 
}