codeigniter活动记录“where_or”分组 [英] Codeigniter Active Record 'where_or' grouping

查看:132
本文介绍了codeigniter活动记录“where_or”分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是有可能的集团的and_where / or_where / or_like ...语句组合在一起,以免混入其他和/,语句。

东西会导致

  

WHERE城市='我的城市和国家='我的状态'AND(名称,比如%名称1%   或名称LIKE%名2%)

解决方案

是的。 $这个 - > DB-化合物其中()允许你手动编写条款。你可以这样做:

  $这个 - > DB-化合物其中(城市,我的城市);
$这个 - > DB-化合物其中(国家,我的国家);
$这个 - > DB-化合物其中('(如%名称1%或名称LIKE%名2%)的名字,空,假);
 

这是试图反引号添加该条款设置虚假prevents codeIgniter第三个参数。

查看href="http://ellislab.com/$c$cigniter/user-guide/database/active_record.html" rel="nofollow">活动记录文档的 $这个 - > DB->其中(); 解释了四种方法,你可以用它来将其中,条款

Is it possible to group and_where / or_where / or_like... statements together so as not to mix with other and/where statements.

Something that would result in

WHERE city = 'My City' AND state = 'My State' AND (name LIKE %name1% OR name LIKE %name2%)

解决方案

Yes. $this->db->where() allows you to write clauses manually. You could do this:

$this->db->where('city', 'My City');
$this->db->where('state', 'My State');
$this->db->where('(name LIKE %name1% OR name LIKE %name2%)', null, false);

Setting the third parameter for false prevents CodeIgniter from trying to add backticks to the clause.

Check out the Active Record documentation. The section titled $this->db->where(); explains the four methods you can use to set WHERE clauses.

这篇关于codeigniter活动记录“where_or”分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆