gpt4 book ai didi

php - 带数组的 ActiveRecord where_in()

转载 作者:可可西里 更新时间:2023-11-01 07:11:33 26 4
gpt4 key购买 nike

<分区>

我已经尝试了几种不同的方法来解决这个问题,但到目前为止还没有解决方案。我收到此错误消息:

“where 子句”中的未知列“Array”

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() 的帮助,我认为我的一切都是正确的,或者已经尝试了几种不同的方法来正确传递数组。

感谢您的帮助。

编辑:最后我将使用我的 Controller 输出这些数据:

$this->output->set_output(json_encode($data));

出于测试目的,我只是跳过 JSON 并尝试使用 PHP 直接从模型输出数据。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com