私はテーブルを持っています
CREATE TABLE IF NOT EXISTS forum_comments (
comment_id int(11) NOT NULL AUTO_INCREMENT,
comment_by int(11) NOT NULL,
topic_id int(11) NOT NULL,
parent int(11) NOT NULL DEFAULT '0',
comment text NOT NULL,
commented_date datetime NOT NULL,
commented_type enum('user','admin') NOT NULL DEFAULT 'user',
level int(11) NOT NULL DEFAULT '1',
status enum('publish','unpublish','block') NOT NULL,
PRIMARY KEY (comment_id)
)
comment_by
topic_id
投稿されたコメントが投稿されたユーザーIDです
parent
コメントが他のコメントへの返信である場合
comment
コメントテキスト
level
はコメントの深さ(1からnレベル)であり、1はトピックの第1レベルのコメントです。
コメントの深さはn番目のレベルにすることができます。トピックIDでコメントを取得するためのクエリが必要です。
select * from forum_comments where topic_id = 1
トピックIDですべてのコメントを取得したいのですが、コメントには「親」(親はこの返信が投稿された元のコメントIDを示します)とともにコメントテーブルにも保存される返信が必要であり、すべてのコメントと返信はツリービュー形式である必要がありますコメントをツリー形式で表示する必要があるためです。
1 Comment (main comment with "parent" 0)
2 reply (reply with "parent" 1)
3 reply (reply with "parent" 2)
4 reply (reply with "parent" 3)
前もって感謝します