How can I get the top X posts of the past week? I have two tables: td_table - holds info about the post; vote_table - holds the info about the votes that have been made for the posts. The following gives me the top three posts (those that have most votes for), but it gives me the top three of all times.
$query = 'SELECT t.id, t.content, t.userid, t.time FROM tb_table t,
(SELECT *, count(*) AS num FROM vote_table GROUP BY voted_id ORDER BY num desc) u
WHERE u.vote_id=t.id LIMIT 3';
I tried using something like this:
SELECT * FROM vote_table WHERE t.time > date_sub(date(now()), interval 7 day)
But whenever I add this kind of WHERE condition to the above query it either dies (if I add it to the select from vote_table) or it loads an empty page (if it's and AND condition of the last where)...
So... how can I combine those? Call all the information from the query, but only those voted_ids that have been made for the past week?