2013-05-22 88 views
2

我正在使用CodeIgniter形成一个不能正常工作的简单查询。Codeigniter比较大于或小于同一字段的值的ID

我试图获取一个字段,其中action_ id大于1而小于4

举例如下:

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

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

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

回答

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

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

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

参考Active Record

0

看到这个尝试这一个SQL发送到他的功能。

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

0

您可以通过包含整个字符串使用WHERE条件像

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

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

希望这会有所帮助。

相关问题