How could I take a mysql query like this:
SELECT id,title,timestamp,upvotes,downvotes,views FROM {$table} ORDER BY count DESC LIMIT $start_from, 20
and based on the timestamp
(which is a stand开发者_JAVA技巧ard mysql timestamp)
make my mysql not only LIMIT $start_from, 20
but in addition...
Limit by:
if it was made today if it was made between today and a week ago if it was made between today and a month ago
Any ideas?
SELECT id, title, timestamp, upvotes, downvotes, views
FROM {$table}
WHERE timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)
ORDER BY count
DESC LIMIT $start_from, 20
MySQL Reference Manual DATE_SUB
SELECT id,title,timestamp,upvotes,downvotes,views
FROM {$table}
where timestamp >= now() - interval 1 week
SELECT id,title,timestamp,upvotes,downvotes,views
FROM {$table}
where timestamp >= now() - interval 1 month
Add a where clause to check the timestamp for the range you want.
精彩评论