在Codeigniter中的where_in [英] Where_in in codeigniter
问题描述
我正在使用Codeigniter 3建立网站。但是现在我遇到了从数据库获取数据的问题。
I'm using Codeigniter 3 to build a website. But now I have an issue with get data from database.
这是我的模型:
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)获取条件列表:
In Controller, I use an array ($arr_condition) to get list conditional:
$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的条件,我才尝试:
My code working perfectly until I need a condition with Where_in, I tried:
$arr_condtion['Cus_id IN']= array('1,2,3');
但是,它不起作用。
请给我一个解决此问题的理想方法。
Please give me an ideal to resolve this issue.
推荐答案
希望这对您有所帮助:
您可以执行以下操作:
在控制器中,将您的where_in条件与另一个这样的参数一起传递
In controller pass your where_in condition with another parameter like this
$where_in = array('1,2,3');
$result = $this->M_cus_dal->Get($arr_condition,$where_in);
在模型方法中获得 $ where_in
作为第二个参数添加到 where_in
子句中,如下所示:
In model method get $where_in
as second parameter as add it to where_in
clause like this :
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;
}
这篇关于在Codeigniter中的where_in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!