CodeIgniter Forums
If statement in active records query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: If statement in active records query (/thread-47588.html)



If statement in active records query - El Forum - 12-14-2011

[eluser]Unknown[/eluser]
I'm trying to implement a search function into my database query. The IF statement is tripping me up. Can someone please help?

Code:
function get_all_records($search, $limit, $offset) {
  
  $ret['records']=$this->db
   ->select('users.username, records.*')
   ->join('records', 'users.id = records.user_id')
   ->limit($limit, $offset);
  
  if (strlen($search)) {
   ->like('title', $search);
  }
  
   ->get('users')
   ->result();  
    
  $ret['num_rows']= $this->db
   ->count_all('records');
  
  return $ret;
}