我正在使用 Codeigniter 3 构建网站。但是现在我在从数据库中获取数据时遇到了问题。
这是我的模型:
public function Get($arr_condition = null)
{
if(!is_null($arr_condition))
{
$this->db->where($arr_condition);
}
$query = $this->db->get('cus');
if($query->num_rows()>0)
{
return $query->result_array();
}
return false;
}
在 Controller 中,我使用数组 ($arr_condition) 获取条件列表:
$arr_condition['Cus_team'] = 1;
$arr_condition['Cus_user != '] = 2;
$arr_condition['Cus_phone LIKE'] = 09900000;
$arr_condition['Cus_role >'] = 1;
$result = $this->M_cus_dal->Get($arr_condition);
在我需要 Where_in 条件之前,我的代码工作正常,我试过:
$arr_condtion['Cus_id IN']= array('1,2,3');
但是,它不起作用。
请给我一个解决这个问题的理想。
最佳答案
希望这对您有帮助:
你可以这样做:
在 Controller 中用另一个参数传递你的 where_in 条件
$where_in = array('1,2,3');
$result = $this->M_cus_dal->Get($arr_condition,$where_in);
在模型方法中,将 $where_in
作为第二个参数添加到 where_in
子句中,如下所示:
public function Get($arr_condition = null,$where_in = NULL)
{
if(!is_null($arr_condition))
{
$this->db->where($arr_condition);
}
if(! empty($where_in))
{
$this->db->where_in('Cus_id',$where_in);
}
$query = $this->db->get('cus');
if($query->num_rows()>0)
{
return $query->result_array();
}
return false;
}
关于php - Where_in 在 codeigniter 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50861360/