Php 添加模型多个条件的codeigniter
这是我的密码Php 添加模型多个条件的codeigniter,php,codeigniter,web,Php,Codeigniter,Web,这是我的密码 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
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')
);
是的,但是在一个查询中,在我当前的查询中,请在我当前的数组中再添加一个条件,不要更改我的查询,只需再添加一个条件,没有区别。这是一天结束时的查询生成器。没有理由你可以使用
get_where
但不能使用where
只要我写我的模型如果我使用$this->db_,那么我的项目的其他地方就会有问题,所以我不必更改布局,只需添加条件,你只需循环遍历你的条件数组,并为每个条件执行where子句