Php 编码点火器中的_在哪里
我正在使用CodeIgniter3建立一个网站。但现在我遇到了从数据库获取数据的问题 这是我的模型:Php 编码点火器中的_在哪里,php,codeigniter,codeigniter-3,query-builder,Php,Codeigniter,Codeigniter 3,Query Builder,我正在使用CodeIgniter3建立一个网站。但现在我遇到了从数据库获取数据的问题 这是我的模型: public function Get($arr_condition = null) { if(!is_null($arr_condition)) { $this->db->where($arr_condition); } $query = $this->db->get('cus'); if($query-
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;
}
在控制器中,我使用数组($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);
我的代码工作得很好,直到我需要一个_所在的条件,我尝试:
$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);
在model方法中,获取$where_In
作为第二个参数,并将其添加到where_In
子句中,如下所示:
如果您使用where_in,那么您的ID应该在数组中 像这样:
$where_in[] = 1;
$where_in[] = 2;
$where_in[] = 3;
或
谢谢@pradeep,我尝试了第一种方法,但在mysql中的结果是
Cus_id='in(1,2,3)
。因此,我将尝试第二种方法。第二种方法如何呢?获得所需结果的更好方法应该是这样的$arr\u condition['Cus\u id IN']='(1,2,3)'代码>检查它是否工作,但更喜欢第二种方式,请让我知道谢谢@pradeep,我尝试了第二种方式,它工作正常。现在我没有更多的时间,所以我会优化我的功能基础你的理想。再次感谢您!对不起,昨天我用智能手机检查了你的答案是否为绿色。但直到今天我才明白这张支票是怎么回事(
$where_in[] = 1;
$where_in[] = 2;
$where_in[] = 3;
$where_in = array('1','2','3');
$this->db->where_in('Cus_id', $where_in);