Codeigniter DB Query with where, or, and .. and how

I have a request for conditions below (minus select, from, etc.)

$this->db->where('show_year', $yyyy); $this->db->or_where('idn', $idn); $this->db->or_like('post_slug', $idn); 

which forms

 SELECT * FROM (`nyb_articles`) WHERE `show_year` = '2009' OR `idn` = 'the' AND `post_slug` LIKE '%the%' 

However, I am looking for it to be more like

 SELECT * FROM (`nyb_articles`) WHERE `show_year` = '2009' AND (`idn` = 'the' OR `post_slug` LIKE '%the%') 

My problem is that I'm not sure if an active CI record supports this concept, and if so, how would I deal with it since I cannot find it anywhere in the document. No matter how I change like , or_like , where , or_where , I can't even nail something like that. So who has any ideas? I would prefer to stay away from the raw request, if at all possible, but if I need to prepare it and do so, I just don't want to do this.

+6
source share
1 answer

Have you tried this?

 SELECT * FROM (`nyb_articles`) WHERE `show_year` = '2009' AND `idn` = 'the' OR `show_year`='2009' AND `post_slug` LIKE '%the%' 

I think the following expression expresses above:

 $this->db->select(...)->from(...)-> where("show_year","2009")->where("idn","the")-> or_where("show_year","2009")->like("post_slug","%the%") 
+2
source

All Articles