建立评论/发布和回复系统[关闭]

I am trying to build a comment system that has replies which can be tied to a particular comment.

Here is my sample code. I tried joining two tables together to display each reply for different comments.

function get_comments() {
    $query = $this->link->query("SELECT * FROM comments, reply");

    $rowCount = $query->rowCount();

    if ($rowCount >= 1) {
        $result = $query->fetchAll();
    }
    else {
        $result = 0;
    }

    return $result;
}

There is no way enough code there to fulfill what you require. In short you need a comments and a reply table as you have, the reply table should have a field for Comment_ID, and when you loop through each comment to display, have an inner loop that loops through each comment reply and displays it under the current comment you are iterating through.

That SQL query doesn't look like it's joining anything.

Since a reply is also a comment, you might be able to have a table structure like:

table comments
    id
    in_reply_to_id
    commenter_name
    comment_text

The in_reply_to_id refers to the id of the comment that this comment is in reply to.

Then you can query like:

select * from comments where in_reply_to_id = whatever_comment_id

to get all of the replies to the comment that has id equal to whatever_comment_id.