从数组中删除重复值

时间:2014-08-17 06:56:45

标签: php mysql sql codeigniter

我使用MySQL使用CodeIgniter生成了一个数组。 [co_name] =>中的值是重复的,我尝试group_by使用co_id并且它不起作用,但group_by使用order_id。{CodeIgniter {{1}仅适用于group_bygroup_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
        )

1 个答案:

答案 0 :(得分:3)

DISTINCT中使用GROUP_CONCAT,这样它就会连接每个co_name群组不同的order_id

GROUP_CONCAT(DISTINCT tbl_customise_optional.co_name SEPARATOR "<br />" ) as co_name