簡體   English   中英

如何使用codeigniter活動記錄在mysql表的單個字段中搜索多個值?

[英]How to search for multiple values in a single field of mysql table using codeigniter active record?

我必須在codeigniter中使用mysql在一個字段中搜索多個值。 這是我的代碼。

在控制器中

public function vpsearch()
{
  $data['info'] = $this->psearch_m->emp_search_form();

  $this->load->view("employer/result",$data);       

}

IN模型

public function emp_search_form()
{
  $skill = $this->security->xss_clean($this->input->post('ps_skills'));
  $jrole = $this->input->post('ps_jobrole'));


  if ( $jrole !== NULL) 
  {
    return $this->db->get('js_edu_details');
    $this->db->like('js_skills','$skill');
  }
}

考慮到 (../雇主/結果)

foreach($info->result() as $row)
{
  echo $row->js_id."<br/><br/>" ;
}

但是,我正在獲取“ js_edu_details”表中的所有記錄,而不是搜索“技能”的字段。

我要去哪里錯了? 任何幫助,謝謝,謝謝。

嘗試:

public function emp_search_form()
{
    $skill = $this->security->xss_clean($this->input->post('ps_skills'));
    //$skill = $this->input->post('ps_skills', true);  other short way of getting the above result with `xss clean`
    if ( $jrole !== NULL) 
    {
        $this->db->like('js_skills',$skill); #remove the single quote around the `$skill`
        $res = $this->db->get('js_edu_details');
        echo $this->db->last_query(); #try to print the query generated
        return $res;
    }
}

Return語句應在like語句之后

您應該像這樣正確安排代碼

public function emp_search_form()
{
    $ps_skills  =   $this->input->post('ps_skills')
    $skill      = $this->security->xss_clean($ps_skills);

    if ( $jrole !== NULL) 
    {
        $this->db->like('js_skills','$skill');
        return $this->db->get('js_edu_details');
    }
}

您還應該注意,條件永遠不會滿足。 它將始終給出錯誤的undefined variable $jrole

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM