CodeIgniter Active 레코드를 사용하여 MySQL 테이블의 단일 필드에서 여러 값을 검색하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/19853225

문제

CodeIgniter에서 MySQL을 사용하여 필드에서 여러 값을 검색해야합니다. 여기 내 코드를 따릅니다.

컨트롤러에서

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

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

}

모델에서

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

관점에서 IE, (../employer/result)

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

그러나 '기술'을 검색 한 필드 대신 'JS_EDU_DETAILS'테이블에서 모든 레코드를 받고 있습니다.

내가 어디로 잘못 가고 있습니까? Wud B에게 감사의 말을 전하면 미리 고맙습니다.

도움이 되었습니까?

해결책

노력하다:

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top