如何在php中打印一对多关系结果


How can I print one to many relationship result in php?

我得到下表作为我的查询结果。

id     name   celebrity
------------------------
1      A       X
1      A       Y
1      A       Z
2      B       M
2      B       N

我想使用php将此表结果打印如下。

1->A->X,Y,z
2->B->M,N

我用mysql数据库查询后得到上面的表作为关联数组。有人能帮我写一个逻辑来打印上面的表格结果吗。提前谢谢。

您可以通过mysql 制作

select id, name, group_concat(celebrity)  
   from te table
 group by id, name