【问题标题】:How to use array values in where clause in CodeIgniter如何在 CodeIgniter 的 where 子句中使用数组值
【发布时间】:2017-08-16 09:48:21
【问题描述】:
我正在尝试在 where 条件下检查数组值。
我的尝试:
$con=array('ad_no',$ao);
$this->db->where('ad_no',$con);
$query = $this->db->get('duration');
$r = $query->result_array();
但我收到以下错误:
'where 子句'中的未知列'array'
【问题讨论】:
标签:
sql
arrays
codeigniter
loops
【解决方案1】:
也许你可以这样尝试:
$con=array('ad_no' => $ao);
$this->db->where($con);
$query = $this->db->get('duration');
$r = $query->result_array();
我希望这个答案可以帮助你,如果代码没有运行,请注意我。
【解决方案2】:
尝试使用此更新批处理来收集数组中的数据,而不是再次在循环中点击查询。
$data = array();
foreach($ad_no as $key=>$id){
$data[] = array(
'ad_no' => $id
);
}
$query = $this->db->update_batch('duration',$data,'ad_no');
【解决方案3】:
对于在 codeigniter 中使用 where 子句,你也可以这样做:
$data['ad_no'] = $ao;
$query = $this->db->get_where('duration',$data);
$r = $query->result_array();
你的代码看起来也不错。
【解决方案4】:
尝试循环:
foreach($ad_no as $key=>$id){
$this->db->where('ad_no',$id);
$query = $this->db->get('duration');
$r = $query->result_array();
}