Php 如何从数组变量获取查询中的数组值

Php 如何从数组变量获取查询中的数组值,php,codeigniter,Php,Codeigniter,我有一个这样的模型 function show_city_n_area_from_id($data){ // $data is an array of ids $this->db->select('column1'); $this->db->from('table'); $this->db->where('id', $data); $query = $this->db->get(); $query_resul

我有一个这样的模型

function show_city_n_area_from_id($data){ // $data is an array of ids
    $this->db->select('column1');
    $this->db->from('table');
    $this->db->where('id', $data);
    $query = $this->db->get();
    $query_result = $query_array();
    return $query_result;
}
我试图以数组的形式从'column1'中提取所有值,该数组是由多个ID组成的数组'$data'

提前谢谢

我得到一个错误:

“where子句”中的未知列“Array”从
表中选择
column1
,其中
id
=
Array


根据您的评论,
$data
是一个ID数组,因此您需要使用
where_in
如下:

$this->db->where_in('id', $data);
修改代码

function show_city_n_area_from_id($data){ 
   $this->db->select('column1'); 
   $this->db->from('table'); 
   $this->db->where_in('id', $data); 
   $query = $this->db->get(); 
   $query_result = $query_array(); 
   return $query_result; 
}
您还可以探索

更新1:

根据您的注释,对象中有ID,因此可以将其转换为数组,如下所示:

$dbIDS = array();
foreach($data['ids'] as $value){
    $dbIDS[] = $value->vbc_item_id;
}

现在您可以在
中使用
$dbIDS
,其中_in

根据您的评论
$data
是一个ID数组,因此您需要在
中使用
where_in
如下:

$this->db->where_in('id', $data);
修改代码

function show_city_n_area_from_id($data){ 
   $this->db->select('column1'); 
   $this->db->from('table'); 
   $this->db->where_in('id', $data); 
   $query = $this->db->get(); 
   $query_result = $query_array(); 
   return $query_result; 
}
您还可以探索

更新1:

根据您的注释,对象中有ID,因此可以将其转换为数组,如下所示:

$dbIDS = array();
foreach($data['ids'] as $value){
    $dbIDS[] = $value->vbc_item_id;
}

现在,您可以在
where\u in

中使用
$dbIDS
,如果其关联数组打印($data),则在where子句中选择
column1`中的
未知列'Array',出现错误并共享结果和什么不起作用?如果其关联数组打印($data)并共享结果,我会在where子句中从
表中选择
column1`中得到错误
未知列'Array'。。“数组到字符串的转换”&从
表中选择
column1
,其中
id
位于('My Listings',Array,Array,Array)…@codeigniter\u learner其关联数组???打印($data)并共享result@codeigniter_learner数组应该是$data['MyListings'],非常感谢。。现在可以用了。。小更新:“它在将
$query\u array()
更改为
$query->result()
”后工作,因为我在“未定义变量:query\u array”和“函数名必须是字符串”时出错。”。。但这解决了我的问题problem@devprocodeigniter医生现在已经转移到这里,我现在有2个错误。。“数组到字符串的转换”&从
表中选择
column1
,其中
id
位于('My Listings',Array,Array,Array)…@codeigniter\u learner其关联数组???打印($data)并共享result@codeigniter_learner数组应该是$data['MyListings'],非常感谢。。现在可以用了。。小更新:“它在将
$query\u array()
更改为
$query->result()
”后工作,因为我在“未定义变量:query\u array”和“函数名必须是字符串”时出错。”。。但这解决了我的问题problem@devprocodeigniter医生现在已经搬到这里了