向CodeIgniter模型添加多个条件


Adding multiple condition to CodeIgniter model

这是我的代码

public function get_news($NewsId = FALSE)
{
    if ($NewsId === FALSE)
    {
        $query = $this->db->get('news');
        return $query->result_array();
        $config['per_page'];
        $this->uri->segment(3);
    }
    $query = $this->db->get_where('news',
                             array('NewsId' => $NewsId,
                                    'Language' => '2');
    return $query->row_array();
}

如果我删除语言条件,它就不能工作了

在up代码中,我想再添加一个条件,如当前是NewId => $NewsId,我想在代码中再添加一个LanId = $LanId

$this-db->where(field1,condition1);
$this-db->where(field2,condition2);
$this-db->where(field3,condition3);
$this->db->get(table);

你可以任意设置

实际上没有区别。但既然你坚持,

$this->db->get_where('table',
    array('field1'=>'condition1',
          'field2'=>'condition2',
          'field3'=>'condition3')
);