如何以大多数视图显示前10名?

时间:2014-04-25 10:32:41

标签: php mysql

我想在我的网站上显示十大种子种子,但是根据点击次数(观点)&添加日期。

我在这里使用此代码的代码显示了前十大种子种子。但是我希望展示过去24小时前十大种子种子。经过24小时的洪流上传。它应该被最近24小时的下一个种子洪流取代。

$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应显示在顶部。

2 个答案:

答案 0 :(得分:0)

只需添加到WHERE子句:

WHERE visible = 'yes' AND banned = 'no' 
AND categories.parent_cat= 'Movie'
AND torrents.uploaded_date > DATE_SUB(NOW(), INTERVAL 1 DAY)

答案 1 :(得分:0)

您的种子表架构是什么?

是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
";