【问题标题】:codeigniter: where query in not condition [duplicate]codeigniter:在非条件下查询 [重复]
【发布时间】:2013-05-19 23:35:02
【问题描述】:

如果此查询选择所有 id =11 的记录

 $this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20);
 $query = $this->db->get();

那么在CodeIgniter 样式中选择id != 11 的所有记录的查询是什么。

【问题讨论】:

标签: php codeigniter


【解决方案1】:

只需将它添加到where的列部分,所以

$this->db->select('title')->from('mytable')->where('id !=', $id)->limit(10, 20);
$query = $this->db->get();

顺便说一句,请务必查看 codeigniter 手册,它在 where() documentation 中直接提及,这是您能找到的最好的文档之一。

【讨论】:

    【解决方案2】:

    这可能有效:

    $this->db->select('title')->from('mytable')->where('id !=', $id)->limit(10, 20);
     $query = $this->db->get();
    

    【讨论】:

      【解决方案3】:

      这也是一种专业干净的方式:)

      $where(array('id !' => $id, 'qty >' => '10'));
              $this->db->select('title');
              $this->db->from('mytable');
              $this->db->where($where);
              $this->db->limit(10, 20);
              $query = $this->db->get();
      

      【讨论】:

      • 链式调用(带回车)非常干净,因为它现在有大量(不可读)$this->db->。从 where 函数中取出参数会更糟,因为现在您必须先忽略变量,继续阅读,然后返回并再次阅读。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多