【发布时间】:2013-06-18 23:05:04
【问题描述】:
我已经尝试了几种不同的方法来解决这个问题,但到目前为止还没有解决方案。我收到此错误消息:
“where 子句”中的未知列“数组”
SELECT * FROM (Articles) WHERE id IN (数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组, 数组)
这是我的型号代码:
function getStarNews($user_id) {
$this->db->select('id');
$this->db->where('user_id', $user_id);
$query = $this->db->get('table1');
foreach ($query->result_array() as $id)
{
//echo $id['id']."<br>"; //displays all of the correct ids I am trying to pass to the where_in()
}
$id = $query->result_array();
$this->db->where_in('id', $id); //pass array of 'id' from above query
$data = $this->db->get('Articles');
return $data->result_array();
}
如果我将 id 数组更改为仅包含 1 个值,则 where_in() 子句可以正常工作并输出与单个“id”匹配的数据行。
在使用 where_in() 时,我查看了整个堆栈和谷歌以寻求帮助,我认为我一切都正确,或者尝试了几种不同的方法来正确传递数组。
感谢您的帮助。
编辑:最后我将使用我的控制器输出这些数据:
$this->output->set_output(json_encode($data));
出于测试目的,我只是跳过 JSON 并尝试使用 PHP 直接从模型中输出数据。
【问题讨论】:
标签: php mysql codeigniter activerecord