您好我正在尝试从表主题中检索我的主题,但在我的查找列表中,我希望显示最新的活动主题,所有注释都在不同的表中。我怎么能这样做,我的列表显示了主题表中的所有主题,但根据评论表中的最新日期将它们按顺序排列?
$forums = mysql_query("select * from forumtopic where category='$who' order by date DESC LIMIT " . (($page - 1) * 10) . ", 10");
while($ forum = mysql_fetch_array($ forums)) {
所以我希望它像
$forums = mysql_query("select * from forumtopic where category='$who' and select from forumcomment where category='$who' but order by date from forumcomment DESC LIMIT " . (($page - 1) * 10) . ", 10");
while($ forum = mysql_fetch_array($ forums)) {
如果这是有道理的
答案 0 :(得分:0)
我相信这就是你想要做的事情:
SELECT * FROM forumtopic
WHERE category='$who'
ORDER BY FIELD( topic,
(SELECT topic
FROM forumcomment
WHERE category='$who'
ORDER BY date DESC))
LIMIT " . (($page - 1) * 10) . ", 10
order by字段允许您指定表forumtopic的订单,该表由最活跃的订购,我也不知道您的表的架构,因此您必须相应地更改名称
编辑 - 简化解决方案,然后加入
SELECT forumtopic.topic FROM forumtopic
INNER JOIN forumcomment
ON forumtopic.topic = forumcomment.topic
WHERE category = '$who'
ORDER BY forumcomment.date DESC
LIMIT " . (($page - 1) * 10) . ", 10