string(1) "8"[2]=> string(2 ) "11"[3]=> 字符串(2) "-6ren">
gpt4 book ai didi

php - 无法使用数组中的 where 子句选择数据

转载 作者:行者123 更新时间:2023-11-29 01:53:35 26 4
gpt4 key购买 nike

我有一个数组 $DeptID :array(5) { [0]=> string(1) "2"[1]=> string(1) "8"[2]=> string(2 ) "11"[3]=> 字符串(2) "15"[4]=> 字符串(2) "17"然后,我想从 MySQL 数据库中选择以获取数组中 DeptID 的数据。我的查询:

$DeptdID = implode(',', $DeptID);
$this->db->select(*)
->from('tabel_data')
->where('DeptID IN ('.$DeptID.')')
->group_by('DeptID', 'ASC')
->get(''):

但是出现错误。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near (Array) GROUP BY `DeptID` at line 6. 

也许有人可以给我一个解决方案

最佳答案

由于您使用的是 CodeIgniter,因此您可以尝试使用 where_in 函数代替 implodewherewhere_in 方法将为您执行此操作。

$this->db->select(*)
->from('tabel_data')
->where_in('DeptID', $DeptID)
->group_by('DeptID', 'ASC')
->get(''):

关于php - 无法使用数组中的 where 子句选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822988/

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