Currently, I am developing a commenting system where users can leave comments and reply to existing comments. In the MySQL database image
If you are curious, in the lower image...
reply_id being Null indicates that the comment has no replies.
parent_comment_id: corresponds to the comment_id. This signifies that the reply_comment is in response to the comment with that specific comment_id. Apologies for the confusing explanation.
=========What I am aiming for===========
Initial comment.
I have replied to the initial comment.
This is my second response.
Hey...
You got owned, buddy.
My Attempt. It's not functioning. I struggle with JavaScript. I am encountering an "comment is not defined" error. My approach may be flawed, but it provides an insight into what I am attempting to achieve
for(var i = 0; i < comments[0].length; i++) {
if(comments[0][i].reply_comment && comments[0][i].comment == comments[0][i+1].comment || comments[0][i].comment != comments[0][i-1].comment ) {
console.log(comments[0][i].comment)
console.log(comments[0][i].reply_comment)
}
else {
console.log(comments[0][i].reply_comment)
}
}