I’m building a website with points system, similar to Stackoverflow;
This is the code I’m using to display top users (for all time):
SELECT id, username, active, points
FROM users
WHERE active='1'
ORDER BY points DESC
But how can I show the top users in 24 hours (also points)?
You would have to make a special table that would record when (and how many) points the user received.
EDIT
E.g. table
pointsThen you just ask for the points awarded today with
WHERE time > UNIX_TIMESTAMP(CURDATE())or in the last 24 hoursWHERE time > UNIX_TIMESTAMP()-24*3600.Example use:
I’d also suggest adding a LIMIT to the query, especially if your site grows big.