0

我的新闻表有日期列和视图列,我想排序并显示具有高观众人数的最新新闻。下面的查询将显示去年(我开始发帖时)浏览次数最多的新闻。但是如何显示最近两天浏览最多的新闻。

 $db->query("select * from news where news_category_id=1 order by views desc limit 0,2"); 

编辑后

 $date= date("d M Y", $dis['ondate']); \\ ondate is in 13912820 format so changed the date format
 $date = mysql_real_escape_string($date); 
 $sel = $db->query("select * from mov_news where news_category_id=1 and '$date'>=DATE_ADD(NOW(), INTERVAL -2 DAY) order by views desc limit 0,2"); 
4

2 回答 2

3
select * from news 
where 
  news_category_id=1 
  and news_date>=UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL -2 DAY))
order by views desc 
limit 0,2
于 2013-06-14T10:17:36.370 回答
1

使用此查询

select * from news 
where your_date_column >= unix_timestamp((CURDATE() - INTERVAL 2 DAY))
AND news_category_id=1 order by views desc
于 2013-06-14T10:17:41.253 回答