6

我在下面查询它的条件(减去选择、来自等)

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

哪些形式

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

但是我希望它更像

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

我的问题是我不确定 CI 的活动记录是否支持这个概念,如果支持,我将如何解决它,因为我在文档的任何地方都找不到它的概念。无论我如何改变like, or_like, whereor_where我什至无法确定类似的东西。所以有人有任何想法吗?如果可能的话,我宁愿远离原始查询,但如果我必须准备一个并这样做,我会,只是不想这样做。

4

1 回答 1

2

你试过这个吗?

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

我认为以下会产生上面的表达式:

$this->db->select(...)->from(...)->
where("show_year","2009")->where("idn","the")->
or_where("show_year","2009")->like("post_slug","%the%")
于 2012-11-18T13:41:14.090 回答