Where and Like query in Codeigniter

take below, using Query Builder Class:

public function search($saq)
{
    $array=$this->db
         ->select()
         ->order_by('id', 'DESC')       
         ->where("name Like '$saq%'")                    
         ->get('products');
    return $array->result();
}

Would this give a correct CodeIgniter query ?

Upvotes: 1

Views: 1143

Answers (1)

Vickel
Vickel

Reputation: 8007

Codeigniter's query builder has a function like() you can use, using your example:

public function search($saq) {
  $query=$this->db
         ->select()
         ->order_by('id', 'DESC')       
         ->like('name', $saq, 'after')                    
         ->get('products');
  return $query->result();
}

more information here

Upvotes: 2

Related Questions