我正在使用CodeIgniter形成一个不能正常工作的简单查询。Codeigniter比较大于或小于同一字段的值的ID
我试图获取一个字段,其中action_ id
大于1而小于4
举例如下:
$this->db->where('newsfeeds.action >', '1');
$this->db->where('newsfeeds.action <', '4');
但是我不知道如果因为我引用了两次相同的字段,CodeIgniter不知道如何运行查询。
我正在使用CodeIgniter形成一个不能正常工作的简单查询。Codeigniter比较大于或小于同一字段的值的ID
我试图获取一个字段,其中action_ id
大于1而小于4
举例如下:
$this->db->where('newsfeeds.action >', '1');
$this->db->where('newsfeeds.action <', '4');
但是我不知道如果因为我引用了两次相同的字段,CodeIgniter不知道如何运行查询。
我觉得你应该给那些条件的数组,并通过get_where功能通过他们
入住这 http://ellislab.com/codeigniter/user-guide/database/active_record.html
试试这个:
$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();
您可以使用多个条件$this->db->where
像
$where= array('newsfeeds.action >' =>1, 'newsfeeds.action <' => 4)
$this->db->where($where);
看到这个尝试这一个SQL发送到他的功能。
$this->db->query($sql);
您可以通过包含整个字符串使用WHERE条件像
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
希望这会有所帮助。