on-internet
← Community

Encapsulate a dynamic number of OR LIKE conditions with parentheses using CodeIgniter's active record methods [duplicate]

Stack Overflow ·

I'm producing a query like the following using ActiveRecord SELECT * FROM (`foods`) WHERE `type` = 'fruits' AND `tags` LIKE '%green%' OR `tags` LIKE '%blue%' OR `tags` LIKE '%red%' The number of tags and values is unknown. Arrays are created dynamically. Below I added a possible array. $tags = array ( '0' => 'green'. '1' => 'blue', '2' => 'red' ); Having an array of tags, I use the following loop to create the query I posted on top. $this->db->where('type', $type); //var type is retrieved from input value foreach($tags as $tag): $this->db->or_like('tags', $tag); endforeach; The issue: I need t

Comments

Sign in or sign up to comment and upvote.

No comments yet.