凹凸系统(显示最近显示的主题,并在顶部显示回复) [英] Bump System (Show recent thread with reply on top)

查看:76
本文介绍了凹凸系统(显示最近显示的主题,并在顶部显示回复)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我使用以下命令对论坛中的所有主题进行排序:

For now I sort all the threads in my forum using this:

SELECT * FROM board ORDER BY id DESC LIMIT 50

这显示了在顶部创建的最新线程,但是我该如何显示具有最近答复的线程,同时又在顶部显示一个新线程?

This shows the newest thread created on the top, but how would I go about showing the thread that has the most recent reply but also showing a new thread on the top?

示例:

  1. 这是一个新线程
  2. 这是旧线程
  3. 这是旧线程
  1. This is a new thread
  2. This is a old thread
  3. This is a old thread

收件人:

  1. 这是一个有新回复的旧主题
  2. 这是一个没有回复的新话题
  3. 这是旧线程
  1. This is a old thread with a new reply
  2. this is a new thread without replies
  3. This is a old thread

如果有帮助,这是回复代码:

This is the reply code if thats any help:

$sql="INSERT INTO reply (id, name, subject, maintext, ip, date, img)

VALUES

('$idid','$name','$subject','$maintext','$encoded','$date','$image_name')";

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

mysql_query("UPDATE board SET replycount = replycount + 1 WHERE id = $idid");

推荐答案

如果我理解您的问题,则希望同时按照最近的回复和最新的话题进行排序.没有关于表的更多信息,我无法为您提供确切的语法,但是您的查询可能看起来像这样:

If I understand your question, you want to sort by both recent replies and newest threads. I can't give you exact syntax without more information about your tables, but your query might look something like this:

SELECT *
FROM board
ORDER BY GREATEST(replyDateTime, creationDateTime)
LIMIT 50;

这使用 GREATEST 函数可以按replyDateTimecreationDateTime ...对每行进行排序,以较新的为准.

This uses the GREATEST function to sort each row by either replyDateTime, or creationDateTime... whichever is more recent.

将您的回复信息放在单独的表格中,您的查询可以使用左联接,然后为板中的每个帖子选择最新的回复...,然后使用GREATEST选择该帖子的创建日期,或帖子的最新回复.

With your reply information in a separate table, your query could use a left join, and then select the most recent reply for each post in board... and then use GREATEST to select either the creation date of the post, or the most recent reply of the post.

/* You will need to specify all your columns in board instead of using * */
SELECT b.ID, b.CreationTimeStamp, MAX(r.CreationTimestamp)
FROM 
    board b
    LEFT JOIN replies r ON r.BoardID = b.ID
/* Include all your columns in your select from board here in your group by */
GROUP BY b.ID, b.CreationTimeStamp
ORDER BY GREATEST(b.CreationTimestamp, MAX(r.CreationTimestamp))
LIMIT 50;

这篇关于凹凸系统(显示最近显示的主题,并在顶部显示回复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆