我使用MySQL使用CodeIgniter生成了一个数组。 [co_name] =>
中的值是重复的,我尝试group_by
使用co_id
并且它不起作用,但group_by
使用order_id
。{CodeIgniter {{1}仅适用于group_by
或从group_by
删除重复值的任何其他方法。
[co_name] =>
这是我的代码
Array
(
[0] => stdClass Object
(
[order_date] => 1408255199
[cus_id] => 6
[order_deliver_name] => Jankia
[order_deliver_add_no] => 5085
[order_deliver_add_street] => mapanawathura road
[order_deliver_add_city] => Kandy
[order_deliver_contact] => 0716352632
[order_deliver_date] => 2014-08-12
[order_status] => pending
[emp_id] =>
[cmp_name] => Burger Bun
[co_name] => Put Ham
Put Tomato
Put Ham
Put Tomato
Put Chilli Sauce
Put Tomato
Put Chilli Sauce
Put Ham
Put Chilli Sauce
[order_id] => 28
[quantity] => 10
)
答案 0 :(得分:3)
在DISTINCT
中使用GROUP_CONCAT
,这样它就会连接每个co_name
群组不同的order_id
GROUP_CONCAT(DISTINCT tbl_customise_optional.co_name SEPARATOR "<br />" ) as co_name