如何排序的數據我存儲線程與父/子關係的論壇如下:與父/子關係
CREATE TABLE forum_threads (
thread_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INTEGER UNSIGNED NOT NULL DEFAULT 0,
topic_id INTEGER UNSIGNED NOT NULL,
user_id INTEGER UNSIGNED NOT NULL,
title VARCHAR(100) NOT NULL,
body TEXT NOT NULL,
create_date DATETIME NOT NULL,
PRIMARY KEY (thread_id),
FOREIGN KEY (parent_id)
REFERENCES forum_threads(thread_id),
FOREIGN KEY (topic_id)
REFERENCES forum_topics(topic_id),
FOREIGN KEY (user_id)
REFERENCES users(user_id)
);
新線程具有parent_id = 0
,而回復有parent_id = the thread being replied to
。現在我很困惑的是,我想顯示最近回覆排序的線程列表:
SELECT * FROM forum_threads
WHERE topic_id = :topic_id AND parent_id = 0
ORDER BY ??? DESC LIMIT :start, :display
不確定如何完成此操作?
外界問題對我來說:':'是什麼意思? (前':topic_id'或':start'? –
@PRPGFerret我正在使用一個PDO包裝器,':'是一個佔位符,用於準備語句。 –