Parsing one col of multiple rows php

后端 未结 3 466
野的像风
野的像风 2021-01-26 03:35

I have e.g. the following data returned from a query, each name is an item:

id      name      comment
1       FF        hey
1       FF        hey back!
2       L         


        
3条回答
  •  滥情空心
    2021-01-26 04:14

    If you are not getting the data back sorted by id already, add to the end of your query:

    ORDER BY name
    

    which will retrieve the same list ordered by id. Then in your while loop, add a variable that keeps track of the last item name that you saw. If it changes, add a new li, otherwise, add the comment on to the end of your current list.

提交回复
热议问题