php - 如何显示浏览量最多的前10名?

标签 php mysql

我想在我的网站上显示排名前 10 的种子种子,但要根据点击次数(浏览次数)和添加日期来显示。

这是我正在使用的代码,该代码显示了前 10 个种子最多的种子。但我想显示过去 24 小时内种子最多的 10 种种子。上传 24 小时的 torrent 后。它应该被最近 24 小时内下一个种子最多的 torrent 替换。

$movie = "
SELECT t.id
     , t.anon
     , t.announce
     , t.category
     , t.leechers
     , t.nfo
     , t.seeders
     , t.name
     , t.times_completed
     , t.size
     , t.added
     , t.comments
     , t.numfiles
     , t.filename
     , t.owner
     , t.external
     , t.freeleech
     , c.name AS cat_name
     , c.image AS cat_pic
     , c.parent_cat AS cat_parent
     , u.username
     , u.privacy
     , IF(t.numratings < 2, NULL, ROUND(t.ratingsum / t.numratings,1)) rating
  FROM torrents t
  LEFT 
  JOIN categories c
    ON c.id = t.category 
  LEFT 
  JOIN users u
    ON u.id = t.owner
 WHERE visible = 'yes' 
   AND banned = 'no' 
   AND c.parent_cat = 'Movie'  
 ORDER 
    BY t.seeders + t.leechers + t.hits DESC
     , t.seeders DESC
     , t.added DESC 
 LIMIT 10
";

请解决这个问题,我从上个月开始就试图解决这个问题。或者如果可能的话,过去 24 小时内观看次数最多的 Torrent 应显示在顶部。

最佳答案

您的 torrent 表架构是什么?

是torrents.added DATETIME 列还是unix 时间戳的常规INT?

$movie = "
SELECT t.id
     , t.anon
     , t.announce
     , t.category
     , t.leechers
     , t.nfo
     , t.seeders
     , t.name
     , t.times_completed
     , t.size
     , t.added
     , t.comments
     , t.numfiles
     , t.filename
     , t.owner
     , t.external
     , t.freeleech
     , c.name AS cat_name
     , c.image AS cat_pic
     , c.parent_cat AS cat_parent
     , u.username
     , u.privacy
     , IF(t.numratings < 2, NULL, ROUND(t.ratingsum / t.numratings,1)) rating
  FROM torrents t
  LEFT 
  JOIN categories c
    ON c.id = t.category 
  LEFT 
  JOIN users u
    ON u.id = t.owner
 WHERE visible = 'yes' 
   AND banned = 'no' 
   AND c.parent_cat = 'Movie'  
   AND t.added > DATE_SUB(NOW(), INTERVAL 1 DAY)
 ORDER 
    BY t.seeders + t.leechers + t.hits DESC
     , t.seeders DESC
     , t.added DESC 
 LIMIT 10
";

关于php - 如何显示浏览量最多的前10名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23290609/

相关文章:

php - 使用 php 将 mysql 查询导出到可下载的 .csv 文件

php - 在 PHP 中缩短文本字符串

php - 转换为 PDO,在引用的 $_POST 中获取 '' 插入数据库

php - PHP 表单的 SQL 注入(inject)威胁?

php - 我如何在 while 循环中回显来自 mysql 的两条不同记录

php - 使用 PHP 更新 MySQL 条目

javascript - 将 td 值传递给 JavaScript

java - 如何使用 mysql 解决 Spring Boot 应用程序上的 "Communications link failure"问题?

mysql - 改进我的查询

Mysql select查询,将列数据有条件地分割成2个新列