If I'm following what you are saying. The following is a very basic way you could do it, maybe created in a while loop? There are other things you can do with this code, but I think it's a good building block.

It completely depends on the way that you're interacting with your database. assuming you're using PDO (which you should be), executing a query that returns the comments will also set your statement's rowCount() equal to the number of records returned.