phpcodeigniterwhere-clausequery-builderwhere-in

Codeigniter query builder WHERE clause method to check if column value exists in a whitelist


I have a table in my database with adminId and clientId

There might be 20 records with the adminId of the logged in user and I'm trying to pull a list of clients.

I am wondering if there is a way i can say something like:

$this->db->where('id', '20 || 15 || 22 || 46 || 86');

I'm trying to do this with dynamic data (you never know how many clients Ids you'll need to pull).


Solution

  • $this->db->where_in('id', ['20','15','22','42','86']);
    

    Reference: where_in