Jump to content

Comment component with nested replies


formasfunction

Recommended Posts

I'm looking for a simple tutorial on how to create a comment section for a website that allows users to reply to previous comments, indenting them much in the same way a site like slashdot does.  I have a working script for a simple list but I'm not sure how to write a recursive function to deal with the rest of it.  I've done quite a few searches for previous solutions but I get the feeling I'm not using the right terms.  Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/68969-comment-component-with-nested-replies/
Share on other sites

I'm not exactly sure how to write the actual recursive function that will take an array returned from a MySQL table named COMMENTS with the following columns:

id

comment

parent_id

timestamp

 

Comments without a parent_id are top level and ordered by the timestamp.  However, any comment with a parent_id will need to be ordered under the comment who's id matches the parent_id, secondarily by it's timestamp.

 

A straight loop won't allow me to take the parent_id's into account.  I'd like to do it all with just one hit to the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.