How to make comment reply query in MYSQL?

后端 未结 3 1010
心在旅途
心在旅途 2020-12-16 22:29

I am having comment reply (only till one level) functionality. All comments can have as many as replies but no replies can have their further replies.

So my database

3条回答
  •  天涯浪人
    2020-12-16 22:56

    If you / somebody is looking for simple solution, then it might be helpfull.

    Structure Change - I suppose you have changed it by adding Blog ID, If there is no blog ID, how do you say which comments are specific to a Blog?

    First do this, it won't harm anything to your database,

    update `tblcomments` set ParentId=Id where ParentId=0;
    

    then to get the blog comments and comment replies in order (comment - reply 1, reply 2... under the comment)

    use the bleow query

    SELECT * 
    FROM  tblcomments 
    ORDER BY  ParentId ASC;
    

    Cheers, -PM.

提交回复
热议问题