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 Id's you'll need to pull). Any ideas?
Active Record ClassCodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.
Use the below query to display the query string: print_r($this->db->last_query()); To display the query result follow this: print_r($query);
$this->db->where_in('id', ['20','15','22','42','86']);
Reference: where_in
Use where_in()
$ids = array('20', '15', '22', '46', '86'); $this->db->where_in('id', $ids );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With