0

我的关系表如下所示:

`relationships` (`relationship_id`, `relationship_individual`, `parent_id`, `partner_id`) VALUES
(28, 160, 161, NULL),
(29, 161, 163, 162),
(30, 162, NULL, 161),
(31, 163, NULL, 164),
(32, 164, NULL, 163),
(34, 166, NULL, 165),
(36, 165, NULL, 166);

我想只显示一次合作伙伴。我试着这样做:

foreach($tree as $child) {
    foreach($tree as $c) {
        if($child['relationship_individual'] != $c['relationship_individual'] && $child['partner_id'] == $c['relationship_individual']){
        unset($tree[$child['partner_id']]);
        }
    }
}
print_r($tree);

但它不起作用,什么也没有发生。我应该怎么办?

4

1 回答 1

0

您可以保留重复项,但在获取它们时,您可能需要执行 DISTINCT MySQL 查询。

MySQL DISTINCT 帮助

于 2013-08-12T17:02:21.043 回答