【发布时间】:2016-04-21 18:00:47
【问题描述】:
我有一个数组 $DeptID :array(5) { [0]=> string(1) "2" [1]=> string(1) "8" [2]=> string(2) "11" [3]=> string(2) "15" [4]=> string(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.
也许有人可以给我一个解决方案
【问题讨论】:
-
您的意思是 order_by 而不是 group_by?
-
哦,是的。对不起,实际上,我的查询很长,但我把它删掉了,所以人们可以简单地阅读它
-
看起来您拼写错误或在
where子句中引用了错误的变量。尝试在where()中引用$DeptdID或在第一行中将$DeptdID更改为$DeptID。
标签: php mysql arrays codeigniter