كيفية البحث عن قيم متعددة في حقل واحد من جدول MySQL باستخدام السجل النشط CodeignIter؟

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

سؤال

لا بد لي من البحث عن قيم متعددة في حقل باستخدام mySQL في codeigniter. هنا يتبع الكود الخاص بي.

في وحدة التحكم

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

في رؤيه أي ، (../employer/result)

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

ومع ذلك ، أحصل على جميع السجلات في جدول "JS_EDU_Details" بدلاً من الحقول التي بحثت "مهارات".

أين أخطأ؟ أي مساعدة wud ب نقدر ، شكرا مقدما.

هل كانت مفيدة؟

المحلول

محاولة:

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