Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.