【发布时间】:2013-12-30 21:41:47
【问题描述】:
我想知道如何将 where_in() 函数中内置的 CodeIgnitors 与多维数组一起使用。到目前为止,我是这样做的,但我得到一个数组字符串转换错误。
示例数组:(数组是动态的,会根据用户输入的内容而变化)
array([0]=>'hello',[1]=>'goodbye');
我的模特:
$this->db->where_in('Column',$array);
$query = $this->db->get('Table');
$result = $query->result();
foreach ($result as $row) {
$vID = $row->ID;
$this->db->insert('Table2', array('ID' => $id, 'val' => $vID));
}
我收到以下错误:
Message: Array to string conversion
Filename: database/DB_active_rec.php
Line Number: 555
还有这个:
Error Number: 1054
Unknown column 'Array' in 'where clause'
SELECT * FROM (`Tags`) WHERE `Tags` IN (Array)
【问题讨论】:
-
您的
$array是什么样的?你确定它是“多维”的吗?where_in不适用于多维数组。此外,您不能在insert中执行val' => $array。也许你想要$this->db->insert_batch? -
对不起,这是一个错误,使用多维数组的解决方法是什么?
-
你的数组真的是什么样子的?您可能需要
foreach覆盖它并为里面的每个数组运行它。
标签: php arrays codeigniter activerecord