samedi 19 août 2017

How to console.log each comment and reply?

Im making a commenting system. People can comment. And people can reply to comments. In the mysql picture

Picture

reply_id if Null means the comment has no replies.

parent_comment_id: matches the comment_id. This means that the reply_comment replied to that comment of the comment_id Sorry for bad explantion.

=========What I want===========

First comment.

I replied to the first comment.

This is my second reply.

Brah...

What I tried. Not working. Im bad at Javascript. I got "comment is not defined" error

 if(comment[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)
 } 

Aucun commentaire:

Enregistrer un commentaire