Codeigniter - 带有 activerecord 的括号?

发布于 2024-11-10 07:55:47 字数 169 浏览 0 评论 0原文

如何在 Codeigniter 的活动记录 SQL 查询中使用圆括号符号? 例如如何完成

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'

How to have round brackets symbol in Codeigniter's active record SQL queries?
e.g. how to accomplish

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乞讨 2024-11-17 07:55:47
$where="(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where, NULL, FALSE);

对于 AND 条件使用

$this->db->where('shopid <>', '18')

$where="(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where, NULL, FALSE);
$this->db->where('shopid <>', '18')
$where="(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where, NULL, FALSE);

and for the AND condition use

$this->db->where('shopid <>', '18')

ie

$where="(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where, NULL, FALSE);
$this->db->where('shopid <>', '18')
绅刃 2024-11-17 07:55:47

我认为你可以这样做:

$where = "(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where)  // or statement here
         ->where('shopid <>', '18') // chaining with AND
         ->get('shops');

不完全确定语法,我正在写这个。如果这不起作用,我回家后会看看。

I think you could do something like:

$where = "(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where)  // or statement here
         ->where('shopid <>', '18') // chaining with AND
         ->get('shops');

Not entirely sure about the syntax, I'm writing this off the top of my head. I'll take a look at it when I get home if this doesn't work.

挥剑断情 2024-11-17 07:55:47

你可以这样做:

$this->db->select('field')->from('shops')->where("(`shopid` = '10' OR `shopid` = '11'")->where("`shopid` <> '18'");
$query = $this->db->get();

您可以编写自己的子句
手动:

$where = "name='Joe' AND status='boss'
或状态='活动'";

$this->db->where($where);

来源:http://www.codeignitor.com/user_guide/database/active_record.html#where

You can just do something like:

$this->db->select('field')->from('shops')->where("(`shopid` = '10' OR `shopid` = '11'")->where("`shopid` <> '18'");
$query = $this->db->get();

You can write your own clauses
manually:

$where = "name='Joe' AND status='boss'
OR status='active'";

$this->db->where($where);

Source: http://www.codeignitor.com/user_guide/database/active_record.html#where

日裸衫吸 2024-11-17 07:55:47
$this->db->select()
         ->from('shops')
         ->where("'(`shopid` = '10' OR `shopid` = '11')")
         ->where('shopid !=', 18);

$this->db->get()->result();
$this->db->select()
         ->from('shops')
         ->where("'(`shopid` = '10' OR `shopid` = '11')")
         ->where('shopid !=', 18);

$this->db->get()->result();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文