我有兩個表一個是「forum_topic」和第二個是「forum_comments」PHP MySQL查詢在笨
我希望有一個笨查詢得到forum_topic細節,比如我有一個查詢從forum_topic其中「SELECT * topic_id = 1「然後我想從forum_comments表基於」forum_comments.topic_id = forum_topic.topic_id「的所有評論,但論壇評論應該是樹形視圖格式,因爲我們也有每個評論的n級回覆也存儲在「forum_comments」表中,您可以在forum_comments表中看到有一個字段「parent」,其中包含「comment_id」,對其進行回覆。
1 - forum_topic
CREATE TABLE IF NOT EXISTS `forum_topic` (
`topic_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`category` int(11) NOT NULL,
`content` text NOT NULL,
`created_by` int(11) NOT NULL,
`created_date` datetime NOT NULL,
`view_count` int(11) NOT NULL,
`last_activity` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` enum('publish','unpublish') NOT NULL,
PRIMARY KEY (`topic_id`)
)
2 - forum_comments
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',
`status` enum('publish','unpublish','block') NOT NULL,
PRIMARY KEY (`comment_id`)
)
你有什麼試過..? – Gautam3164 2013-03-13 06:40:38
我用自定義代碼嘗試過,激發多個查詢 – 2013-03-13 06:43:33
所以你只需要基於論壇主題的主題標識進行評論? – 2013-03-13 06:44:40