【问题标题】:Codeigniter - brackets with activerecord?Codeigniter - 带活动记录的括号?
【发布时间】:2011-05-30 11:38:38
【问题描述】:

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

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

【问题讨论】:

标签: codeigniter activerecord


【解决方案1】:
$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')

【讨论】:

    【解决方案2】:

    我认为你可以这样做:

    $where = "(`shopid` = '10' OR `shopid` = '11')";
    
    $this->db->where($where)  // or statement here
             ->where('shopid <>', '18') // chaining with AND
             ->get('shops');
    

    不完全确定语法,我是在脑海中写下这个。如果这不起作用,我会回家看看。

    【讨论】:

      【解决方案3】:

      你可以这样做:

      $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

      【讨论】:

        【解决方案4】:
        $this->db->select()
                 ->from('shops')
                 ->where("'(`shopid` = '10' OR `shopid` = '11')")
                 ->where('shopid !=', 18);
        
        $this->db->get()->result();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-02-22
          • 1970-01-01
          • 2013-07-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-19
          • 1970-01-01
          相关资源
          最近更新 更多