Where_in 在代码点火器中
Where_in in codeigniter
我正在使用 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');
但是,它不起作用。
请给我一个解决这个问题的理想。
希望对您有所帮助:
你可以这样做:
在控制器中用另一个参数传递你的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;
}
如果您使用 where_in 那么您的 ID 应该在数组
中
像这样:
$where_in[] = 1;
$where_in[] = 2;
$where_in[] = 3;
或
$where_in = array('1','2','3');
$this->db->where_in('Cus_id', $where_in);
我正在使用 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');
但是,它不起作用。
请给我一个解决这个问题的理想。
希望对您有所帮助:
你可以这样做:
在控制器中用另一个参数传递你的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;
}
如果您使用 where_in 那么您的 ID 应该在数组
中像这样:
$where_in[] = 1;
$where_in[] = 2;
$where_in[] = 3;
或
$where_in = array('1','2','3');
$this->db->where_in('Cus_id', $where_in);