I’m currently getting “top rated articles” by summing vote values from ‘votes’ table against articles from ‘stories’ table.
Current PHP query:
$sql = mysql_query("SELECT stories.*, SUM(votes.vote_value) as 'total_votes' FROM stories JOIN votes ON stories.id = votes.item_name GROUP BY stories.id ORDER BY total_votes DESC LIMIT 10") or die (mysql_error("There was an error in connection"));
Database Structure:
stories table:

votes table:

But I would like to know how to display information within different time periods. Say show top rated articles “today” “last week” “last month” “last year”. Basing on article creation date st_date from ‘stories’ table. I just need those 4 (today, last week, month, year) different queries or parts that are responsible to get data within different time periods.
1 Answer