Jump to content

Adding reply feature to comment system


ryanmetzler3
Go to solution Solved by scootstah,

Recommended Posts

I have a comment system that basically allows you to post a comment, but you cant reply to any existing comments.

 

Here is the source code for it actually. Basically php sends the comment data to the database. It also sends it to AJAX via a request, then AJAX spits out a JSON object that displays the comments as XHTML.

 

http://tutorialzine.com/2010/06/simple-ajax-commenting-system/

 

I have changed the code a little bit so that users can log in rather than typing their name and email before every comment. I do not think this should matter for what I am trying to accomplish now. Does anyone have any idea how I could add a "reply" link to each comment. Then the reply could display below and slightly indented from the comment they replied to? I have no clue where to even start. 

Link to comment
Share on other sites

  • Solution

The exact solution depends on how you want the nesting to behave. If you only want comments to be nested 1 level deep, then you can just add a "parent_id" column to your comments table. If you want more than 1 level, you'll probably want to go with a hierarchical tree design. Check out this article for more information on that.

Link to comment
Share on other sites

If you only want comments to be nested 1 level deep, then you can just add a "parent_id" column to your comments table.

 

parent_id column in your comments table is all you really need. ie, comment 4 has parent comment 2,  comment 2 has parent comment 1.   comment 3 has parent comment null (null is mind blowing)

You don't need any extra tables to accomplish this.  

 

Comment 1

       Comment 2

             Comment 4

Comment 3

Edited by objnoob
Link to comment
Share on other sites

parent_id column in your comments table is all you really need. ie, comment 4 has parent comment 2,  comment 2 has parent comment 1.   comment 3 has parent comment null (null is mind blowing)

You don't need any extra tables to accomplish this.  

 

Comment 1

       Comment 2

             Comment 4

Comment 3

 

Yes, you can do it that way, but it's much less efficient and overall not very good design. The article that I linked explains the differences.

Link to comment
Share on other sites

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.