title: Multiple Like Clauses Codeigniter
body: <p>I am trying to implement a search box for my website. In my user accounts table, I've divided the accounts into three, namely homeowners, admins, and deactivated users. I want the search function to be able to search across multiple columns (search by username, first name, last name, address, combination of first name and last name). However in my model, my WHERE clause seems to be ignored. In my search_homeowner function, I limit the results to display only the homeowners, but I get results that show the admin ones. I can't seem to have multiple LIKEs so I tried OR like. Here's the code.</p>
  
  <p>Model:</p>
  
  <pre><code>function search_homeowner($searchquery) {
  
      $this-&gt;db-&gt;select('*')-&gt;from('accounts')-&gt;where('role', 0)-&gt; where('isActive', 1);
      $this-&gt;db-&gt;like('firstname',$searchquery,'after');
      $this-&gt;db-&gt;or_like('lastname',$searchquery,'after');
      $this-&gt;db-&gt;or_like('username',$searchquery,'after');
      $this-&gt;db-&gt;or_like('address',$searchquery,'after'); 
  
      $query = $this-&gt;db-&gt;get();
      if($query-&gt;num_rows() &gt; 0) {
          return $query-&gt;result();
      } else {
          return $query-&gt;result();
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>function search_homeowner() {
       $this-&gt;load-&gt;model('model_accounts');
       $searchquery = $this-&gt;input-&gt;post('search');
  
       if(isset($searchquery) and !empty($searchquery)) {
          $data['users'] = $this-&gt;model_accounts-&gt;search_homeowner($searchquery);
          $data['main_content'] = 'view_adminaccounts';
          $data['homeownerlinks']='';
          $this-&gt;load-&gt;view('includes/admin_accounts_template', $data);
       } else {
          redirect('admin_accounts/homeowner');
       }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/GIr7J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GIr7J.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/2f9Wl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2f9Wl.png" alt="enter image description here"></a></p>