Php 如何创建一个;最后25个线程是';我参加了;MySQL页面
我正在为我的论坛在我的网站上创建一个“你以前参与过的25个线程”页面,但我不太明白用什么样的SQL来完成它。它需要进入“回复”表,找到用户最近参与的25个(“海报”列),但它们不能有相同的“主题”列。然后,它需要按照“topic”表中的“last_post”int对其进行排序。“回复”表中的“主题”列对应于“主题”表中的“id”列 有什么帮助吗 表结构:Php 如何创建一个;最后25个线程是';我参加了;MySQL页面,php,mysql,group-by,sql-order-by,forum,Php,Mysql,Group By,Sql Order By,Forum,我正在为我的论坛在我的网站上创建一个“你以前参与过的25个线程”页面,但我不太明白用什么样的SQL来完成它。它需要进入“回复”表,找到用户最近参与的25个(“海报”列),但它们不能有相同的“主题”列。然后,它需要按照“topic”表中的“last_post”int对其进行排序。“回复”表中的“主题”列对应于“主题”表中的“id”列 有什么帮助吗 表结构: --f_topics-- id (int) subject (varchar) poster (varchar) category (int)
--f_topics--
id (int)
subject (varchar)
poster (varchar)
category (int)
posted (varchar)
type (varchar)
last_post (int)
views (int)
locked (int)
--f_replies--
id (int)
poster (varchar)
content (text)
date (varchar)
topic (int)
subject (varchar)
last_post (int)
如果您不熟悉查询参数或PDO,请参阅:
SELECT t.id, t.subject, t.poster, t.category,
t.posted, t.last_post, t.views, t.locked
FROM f_topics t
WHERE EXISTS (
SELECT 1 FROM f_replies r
WHERE r.topic = t.id
AND r.poster = :user -- this is a query parameter, use PDO
)
ORDER BY t.last_post DESC
LIMIT 25