Reputation: 329
I have date column and views column for my news table, I would like to sort and display the most recent news with high viewers count. Below query will display the most viewed news from last year (when i started posting) . But how to display most viewed news for recent 2days .
$db->query("select * from news where news_category_id=1 order by views desc limit 0,2");
After editing
$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");
Upvotes: 0
Views: 101
Reputation: 65314
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
Upvotes: 3
Reputation: 30488
Use this query
select * from news
where your_date_column >= unix_timestamp((CURDATE() - INTERVAL 2 DAY))
AND news_category_id=1 order by views desc
Upvotes: 1