我想在last_name的情况下包含like子句。这是我用于搜索框的控制器代码。我想将表单值last_name与db value family_name进行比较。
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 :(得分:0)
尝试在$this->db->like()
中向查询添加get_volunteers()
。 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() );
}