title: Codeigniter parentheses in dynamic Active Record query
body: <p>I'm producing a query like the following using ActiveRecord</p>
  
  <pre><code>SELECT * FROM (`foods`) WHERE `type` = 'fruits' AND 
         `tags` LIKE '%green%' OR `tags` LIKE '%blue%' OR `tags` LIKE '%red%'
  </code></pre>
  
  <p>The number of <code>tags</code> and values is unknown. Arrays are created dynamically. Below I added a possible array.</p>
  
  <pre><code>$tags = array (                 
          '0'     =&gt; 'green'.
          '1'     =&gt; 'blue',
          '2'     =&gt; 'red'
  );  
  </code></pre>
  
  <p>Having an array of tags, I use the following loop to create the query I posted on top.</p>
  
  <pre><code>$this-&gt;db-&gt;where('type', $type); //var type is retrieved from input value
  
  foreach($tags as $tag):         
       $this-&gt;db-&gt;or_like('tags', $tag);
  endforeach; 
  </code></pre>
  
  <p>The issue: I need to add parentheses around the <code>LIKE</code> clauses like below:</p>
  
  <pre><code>SELECT * FROM (`foods`) WHERE `type` = 'fruits' AND 
        (`tags` LIKE '%green%' OR `tags` LIKE '%blue%' OR `tags` LIKE '%red%')
  </code></pre>
  
  <p>I know how to accomplish this if the content within the parentheses was static but the foreach loop throws me off..</p>