codeigniter:查询处于非条件状态

时间:2013-05-24 11:16:28

标签: php codeigniter

如果此查询选择所有记录,其中id = 11

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

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

3 个答案:

答案 0 :(得分:5)

只需将其添加到where的列部分,即

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

顺便说一句,请务必查看codeigniter手册,它会使用where() documentation提及它,这是您将要找到的最佳文档之一。

答案 1 :(得分:1)

这可能有效:

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

答案 2 :(得分:1)

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

$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();