Good practice way of getting items with subitems from the database and displaying them
I have a list of items. For each item there are sublists. It is kind of like the answers on StackOverflow where each answer has a list of 0-n subcomments.

I am using a PHP script, and I am able to query for all the comments and subcomments in one query, but having a hard time organizing the data to be displayed properly.

The difficulty I am having is getting all the main comments, then aggregating all the subcomments under them, and then dynamically figuring out when to place the form to add extra subcomments.

Any idea how to do this in a more or less elegant or good-practice manner?

Thanks!!
Good practice way of getting items with subitems from the database and displaying them
===

I have a list of items. For each item there are sublists. It is kind of like the answers on StackOverflow where each answer has a list of 0-n subcomments.

I am using a PHP script, and I am able to query for all the comments and subcomments in one query, but having a hard time organizing the data to be displayed properly.

The difficulty I am having is getting all the main comments, then aggregating all the subcomments under them, and then dynamically figuring out when to place the form to add extra subcomments.

Any idea how to do this in a more or less elegant or good-practice manner?

Thanks!!