elimariaaa
elimariaaa

Reputation: 866

Query with multiple likes

All I see is or_like(). Is it possible to query two different 'likes' and both are mandatory?

return $this->db
  ->select('product_key.contact_email, product_key.contact_number, product_key.client_name, product_key.batch_code, product_key.status, product_key.key, payment.paymentdate, product_key.id, payment.notified')
  ->from('product_key')
  ->limit($limit,$offset)
  ->like('product_key.client_name', $filter_name)   
  ->like('product_key.status', $filter_status) //Second like ('AND LIKE' maybe?)
  ->where('status', 'purchased')
  ->select_max('paymentdate','latest_payment')
  ->join('payment', 'payment.keyid=product_key.id', 'left outer')
  ->order_by('client_name', "asc")
  ->group_by('product_key.id')
  ->get()
  ->result();

Upvotes: 1

Views: 83

Answers (2)

elimariaaa
elimariaaa

Reputation: 866

I just added a condition to show an alert if either or both are missing so it won't output anything. Thanks for the help guys! :)

Upvotes: 0

Mudshark
Mudshark

Reputation: 3253

You can pass an array to $this->db->like()which will produce multiple ANDs:

$array = array('product_key.client_name' => $filter_name, 'product_key.status' => $filter_status);
$this->db->like($array); 

Upvotes: 1

Related Questions