title: Codeigniter combine where_in and like active record queries
body: <p>I have the following active record query:</p>
  
  <pre><code>$this-&gt;db-&gt;select('id, email, first_name, last_name, current_location_state, current_location, avatar, avatar_fb');
            $this-&gt;db-&gt;from('users');
            $this-&gt;db-&gt;like('first_name', $search);
            $this-&gt;db-&gt;or_like('last_name', $search);
            $this-&gt;db-&gt;or_like("CONCAT(first_name, ' ', last_name)", $search);
            $this-&gt;db-&gt;or_like('email', $search);
            $this-&gt;db-&gt;where_in('id', $ids);
  </code></pre>
  
  <p>This is a function that has an array $ids, which has the ids of my friends. I want to search for friends that match my "like" queries, but only have one of the id's in the $ids variable.</p>
  
  <p>I'm pretty sure i need to combine where_in and all the like statements so its something like (WHERE_IN $ids &amp;&amp; Like Statements).</p>
  
  <p>I'm not great at mysql so any help here would be appreciated. </p>
  
  <p>Thanks!</p>
  
  <pre><code>function narrow_connections($search) {
  
         //First get all this users connections...
         $connections = $this-&gt;get_connections($this-&gt;session-&gt;userdata('user_id'), 0, 0);
  
         if(empty($connections)) {
            return array();
         }else {
  
            //Need to get an array of id's
            $ids = array();
            foreach($connections as $con) {
               array_push($ids, $con['id']);
            }
  
            //Now that we have an array of ID's, find all users that have one of the ids (our connections), AND match a search term to narrow down
            //the results. 
  
            $this-&gt;db-&gt;select('id, email, first_name, last_name, current_location_state, current_location, avatar, avatar_fb');
            $this-&gt;db-&gt;from('users');
            $this-&gt;db-&gt;like('first_name', $search);
            $this-&gt;db-&gt;or_like('last_name', $search);
            $this-&gt;db-&gt;or_like("CONCAT(first_name, ' ', last_name)", $search);
            $this-&gt;db-&gt;or_like('email', $search);
            $this-&gt;db-&gt;where_in('id', $ids);
            $query = $this-&gt;db-&gt;get();
            $data = array();
  
            foreach ($query-&gt;result() as $row) {
            $data[] = array(
              'id' =&gt; $row-&gt;id,
              'email' =&gt; $row-&gt;email,
              'first_name' =&gt; $row-&gt;first_name,
              'last_name' =&gt; $row-&gt;last_name,
              'current_location_state' =&gt; $row-&gt;current_location_state,
              'current_location' =&gt; $row-&gt;current_location,
              'avatar' =&gt; $row-&gt;avatar,
              'avatar_fb' =&gt; $row-&gt;avatar_fb,
            );
            }
            return $data;
  
         }
       }
  </code></pre>