2

我正在使用 CodeIgniter 形成一个无法正常工作的简单查询。

我试图获得一个action_ id大于 1 但小于 4 的字段。

示例如下:

$this->db->where('newsfeeds.action >', '1');

$this->db->where('newsfeeds.action <', '4');

但是我不确定是否因为我两次引用相同的字段,CodeIgniter 不知道如何运行查询。

4

5 回答 5

1

尝试这个:

$this->db->where('newsfeeds.action >', 1);

$this->db->where('newsfeeds.action <', 4);

或者,如果 where 条件具有静态值,您可以直接执行以下操作:

$this->db->where('newsfeeds.action > 1');

$this->db->where('newsfeeds.action < 4');

并使用以下方式查看查询:

echo $this->db->last_query();
于 2013-05-22T06:11:45.220 回答
0

试试这个把 sql 发送到他的函数。

$this->db->query($sql);

于 2013-05-22T06:19:12.027 回答
0

您可以通过制作一个包含整个 WHERE 条件的字符串来使用它

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

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

希望这会有所帮助。

于 2013-05-22T07:02:42.393 回答
0

我认为您应该在数组中给出这些条件并通过 get_where 函数传递它们

检查这个 http://ellislab.com/codeigniter/user-guide/database/active_record.html

于 2013-05-22T06:07:13.467 回答
0

$this->db->where您可以在like中使用多个条件

$where= array('newsfeeds.action >' =>1, 'newsfeeds.action <' => 4)
$this->db->where($where);

请参阅此以供参考Active Record

于 2013-05-22T06:12:24.543 回答