如何在 codeigniter 中包含 get_where 的多个条件?

How to include multiple condition on get_where in codeigniter?

我试图在我的 get_where 中添加条件,但它不起作用。单一条件有效,但我需要两个条件。有什么想法吗?

这是我的代码:

$query = $this->db->get_where($this::DB_TABLE, array("$column = " => $id, " $column2 = " => $id2, ));

相反,我只是这样做的:

$query = "select * from ".$this::DB_TABLE." name where $column=? and $column2 = ?";

$sql = $this->db->query($query, array($id,$id2));

谢谢,Shaiful Islam :)

据我所知,您正在尝试将 Active Record 与 Query 相结合,因此声明条件的最佳方式是:

$this->db->select('*');
$this->db->from('table');
$this->db->where('table.column', $condition1);
$this->db->where('table.column2', $condition2);
$this->db->where('table.column3', $condition3);
$q = $this->db->get();

foreach($q->result() as $row){
var_dump($row);
}

$this->db->select('*');
$this->db->from('table');
$this->db->where(array('table.column' => $condition1, 'table.column2' => $condition2, 'table.column3' => $condition3));
$q = $this->db->get();

foreach($q->result() as $row){
var_dump($row);
}
$where_array = array(
               $column =>$id,
               $column2=>$id2
              );  
$query = $this->db->get_where($this::DB_TABLE,$where_array);

我发现了一件有 where 条件的东西。可能对你有帮助。

$this->db->group_start(); $this->db->group_end();

试试这个代码

$query = $this->db->get_where('table1,table2', array('table1.$id' => $id,'table2.condition' => $condition));
return $query->result_array();