ryanmetzler3 Posted December 18, 2013 Share Posted December 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284840-adding-reply-feature-to-comment-system/ Share on other sites More sharing options...
Solution scootstah Posted December 18, 2013 Solution Share Posted December 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284840-adding-reply-feature-to-comment-system/#findComment-1462680 Share on other sites More sharing options...
ryanmetzler3 Posted December 19, 2013 Author Share Posted December 19, 2013 Thanks mate! Quote Link to comment https://forums.phpfreaks.com/topic/284840-adding-reply-feature-to-comment-system/#findComment-1462713 Share on other sites More sharing options...
objnoob Posted December 19, 2013 Share Posted December 19, 2013 (edited) 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 December 19, 2013 by objnoob Quote Link to comment https://forums.phpfreaks.com/topic/284840-adding-reply-feature-to-comment-system/#findComment-1462715 Share on other sites More sharing options...
scootstah Posted December 19, 2013 Share Posted December 19, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284840-adding-reply-feature-to-comment-system/#findComment-1462719 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.