How to use $this->db->like and $this->db->where at the same time in codeigniter search form
<p>Hello guys I am trying to learn CI by making a Job Search project in codeigniter. I am trying to make multiple input field job search engine in it. I have three fields in the form. My form is below
<a href="http://i.stack.imgur.com/X59jp.png" rel="nofollow">Form screenshot</a></p>

<p>My controller code is this : </p>

<pre><code>  class Search extends CI_Controller{

    public function normal(){

        $this-&gt;form_validation-&gt;set_rules('job_keywords', 'Job Keywords', 'required');

        if($this-&gt;form_validation-&gt;run() == FALSE){

             $viewdata['main_view'] = 'home';
             $this-&gt;load-&gt;view('layout/main', $viewdata);

        }
        else{
          $search_term = $this-&gt;input-&gt;post('job_keywords');
          $location = $this-&gt;input-&gt;post('job_location');
          $type = $this-&gt;input-&gt;post('job_type');
          $searchdata['search_results'] = $this-&gt;search_model-&gt;default_search($search_term, $location, $type);

                $searchdata['main_view'] = 'search_page';
          $this-&gt;load-&gt;view('layout/main', $searchdata);
        }
    }
</code></pre>

<p>}</p>

<p>My model is:</p>

<pre><code>    public function default_search($search_term, $location="", $type){

    $searchterm = $search_term;

    $this-&gt;db-&gt;like('job_title', $searchterm);
    $this-&gt;db-&gt;or_like('job_description', $search_term);

    $this-&gt;db-&gt;where('type_id', $type); 

    if($location!= ""){
       $this-&gt;db-&gt;like('location_id', $location);   
    }



    $res = $this-&gt;db-&gt;get('jobs');

    if($res-&gt;num_rows() &gt;= 1){
        return $res-&gt;result();
    }
    else{
        return false;
    }

}
</code></pre>

<p>I am getting the search results when I am just using $this->$db->like() and $this->$db->or_like() but when I am using a $this->$db->where() the query doesn't follow the WHERE clause. When I remove $this->$db->or_like(), it works fine but not with two like clause. Can someone please tell me where I am going wrong. Thank you.</p>

<p><a href="http://i.stack.imgur.com/5Jc6M.png" rel="nofollow">Job table structure with 2 rows of data</a></p>