ciel Posted April 26, 2013 Share Posted April 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 26, 2013 Share Posted April 26, 2013 Pass the id of the comment being replied to to the comment page. If they are replying to the topic the id will be that of the first (opening) comment. Quote Link to comment Share on other sites More sharing options...
PaperTiger Posted April 28, 2013 Share Posted April 28, 2013 ^ 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...... ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.