爱玺玺

爱玺玺的生活日记本。wx:lb87626

显标题列表的同时显示对应的评论,group_concat的使用

mysql> select ind.id,group_concat(re.content) from mg_index ind left join mg_reback_msg re on ind.id=re.pid group by id;

+----+--------------------------+

| id | group_concat(re.content) |

+----+--------------------------+

|  1 | NULL                     |

|  2 | NULL                     |

|  3 | NULL                     |

|  4 | NULL                     |

|  5 | NULL                     |

|  6 | sdfsdf,测试              |

|  7 | asdf                     |

+----+--------------------------+

7 rows in set

看第6条,将这个字符串转换成数组在循环出来就可以了。一个sql语句搞定。

发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5