简体   繁体   English

每日/每周/每月高分

[英]Daily/Weekly/Monthly Highscores

I have an online highscores made with php + mysql but it currently shows the All Time highscores, I want to add Daily/Weekly/Monthly to that and I was wondering what would be the best way todo that? 我有一个用php + mysql制作的在线高分,但是当前显示的是所有时间的高分,我想在其中添加每日/每周/每月,我想知道这样做的最佳方法是什么?

My current thought is to add 3 new tables and then have the data inserted into each of them, and then having a cron which would run at the appropriate times to delete the data from each of the tables. 我当前的想法是添加3个新表,然后将数据插入到每个表中,然后创建一个cron,它将在适当的时间运行以从每个表中删除数据。

Is there any better way I could do this? 有什么更好的办法可以做到这一点吗?

Another thing, I want to have it so the page would be highscores.php?t=all t=daily, etc. How would I make it so that the page changed the query depending on that value? 另一件事,我想拥有它,以便页面为highscores.php?t = all t = daily,等等。我如何制作它,以便页面根据该值更改查询?

Thanks. 谢谢。

Use one table and add a column with the date of the highscore. 使用一个表,并在列中添加高分日期。 Then have three different queries for each timespan, eg 然后针对每个时间范围进行三个不同的查询,例如

SELECT ... FROM highscores WHERE date>"05-12-2011";

If you want to have a generic version without the need to have a fixed date, use this one: 如果您想要一个通用版本而不需要一个固定的日期,请使用以下版本:

SELECT ...
FROM highscores
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM