Jump to content

Hierarchy Comments


ciel

Recommended Posts

Hello all

I'm working on a comment script and it works fine but I wanna implement a feature which is hierarchy comments.

I understand that we need to connect a comment/reply with its topic via parent_id and so on for connecting a reply with a reply to it.

my questions are how can we control that when we do the insertion into the replies table? how will the connection via parent_id be made? and how to choose between post a reply to a topic or to another reply?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/277323-hierarchy-comments/
Share on other sites

^ Pretty much that. All you need to do is pass in the parentID and assign that.

 

Consider:

 

ID: 1

comment: "First Comment"

parentID: NULL

 

ID: 2 

comment: "Second Comment"

parentID: 1

 

ID: 3

comment: "Third Comment"

parentID: 2

 

 

By simply specifying the parentID when doing the reply, you can then get a recursive list of all the comments so that you end up with something like:

Comments Array
(
  [0] = Array
          (
               ID: 1, 
               comment: "First comment", 
               parentID: NULL, 
               replies: Array
                            (
                                    [0] = Array 
                                            (
                                                      ID: 2,
                                                      comment: "Second Comment"
                                                      parentID: 1
                                                      replies = etc......
                                            )
                            )
          )
)
Link to comment
https://forums.phpfreaks.com/topic/277323-hierarchy-comments/#findComment-1426904
Share on other sites

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.