title: CodeIgniter with Active Records and or_like
body: <p>I have an admin panel with a view for all the users info gotten from a Database table named "users".</p>
  
  <p>There's a search box and I use Active records to fetch the data. But there seems to be a problem with that and I can't figure it out. I'm pretty sure it's in the <code>or_like</code> part but the error confuses me.</p>
  
  <p>Here is the query I make passing one variable <code>$data</code> posting the info from the search box :</p>
  
  <pre><code>public function get($data) {
  
      $this-&gt;db-&gt;select('id, email, firstname, lastname, usertype, ts_created, ts_last_login, position');
  
      if (isset($data['query']) &amp;&amp; $data['query'] != '') {
          $fields = json_decode($data['fields'], true);
  
          $this-&gt;db-&gt;like($fields[0], $data['query']);
  
          foreach ($fields as $field) {
              $this-&gt;db-&gt;or_like($field, $data['query']);
          }
  
      }
  
      $this-&gt;db-&gt;limit($data['limit'], $data['start']);
      if (isset($data['sort'])) {
          $sort = json_decode($data['sort'], true);
          $this-&gt;db-&gt;order_by($sort[0]['property'], $sort[0]['direction']);
      }
  
      $query = $this-&gt;db-&gt;get('users');
  </code></pre>
  
  <p>Because it's somewhat a refactoring of an existing program, I had to add a new feature - 'groups' which is not part of the users table so I add the key['groups']=>with values looping the query result :</p>
  
  <pre><code>$users = array();
  foreach ($query-&gt;result_array() as $user) {
      $users[] = array_merge($user, array('groups' =&gt;''));
  }
  
  $count = sizeof($users);
  //Adding groups id's as values to the group key         
  foreach ($this-&gt;getGroupsAndUsers() as $group) {
      for ($i = 0; $i &lt; $count; $i++) {
          if ($users[$i]['id'] == $group['user_id']) {
              //Begin check
              if ($users[$i]['groups'] == '') {
                  $users[$i]['groups'] .= $group['group_id'];
              } else {
                  $users[$i]['groups'] .= "," . $group['group_id'];
              }
              //End of check 
          }
      }       
  }
  $result = $users;
  return $result;
  </code></pre>
  
  <p>And with passing the final array to the $result variable this should be all, but when I try to search a certain user I get this error:</p>
  
  <pre><code>&lt;p&gt;Error Number: 1054&lt;/p&gt;&lt;p&gt;Unknown column 'groups' in 'where clause'&lt;/p&gt;&lt;p&gt;SELECT `id`, `email`, `firstname`, `lastname`, `usertype`, `ts_created`, `ts_last_login`, `position`
  FROM (`users`)
  WHERE  `firstname`  LIKE '%stefan%'
  OR  `firstname`  LIKE '%stefan%'
  OR  `lastname`  LIKE '%stefan%'
  OR  `email`  LIKE '%stefan%'
  OR  `position`  LIKE '%stefan%'
  OR  `groups`  LIKE '%stefan%'
  </code></pre>
  
  <p>it says that groups is unknown column and it's missing from the select but I'm not sure it's the real problem cause I actually see the groups and have a UI in the admin panel for it. Also, being a MySQL noob, I think it's kind of strange to get a query like this:</p>
  
  <pre><code>WHERE  `firstname`  LIKE '%stefan%'
      OR  `firstname`  LIKE '%stefan%'
      OR  `lastname`  LIKE '%stefan%'
      OR  `email`  LIKE '%stefan%'
      OR  `position`  LIKE '%stefan%'
      OR  `groups`  LIKE '%stefan%'
  </code></pre>
  
  <p>I mean, is this the normal behaviour of <code>or_like</code> to get the same value?</p>
  
  <p>And at the end, because I'm really lost here, if anyone can help or suggest what could cause this problem would be really appreciated.</p>