比赛入场限制为每天一次
我正在为一个会员网站编写一个 PHP 竞赛脚本,该网站需要将每个会员的条目限制为每天一次。到目前为止,我有以下 MySQL 代码:
SELECT ce_id
FROM competition_entries
WHERE ce_c_id = '$c_id'
AND ce_sub_id = '$user_id'
AND cte_date >= SYSDATE() - INTERVAL 1 DAY
- ce_c_id 是竞赛 ID,
- ce_sub_id 是会员 ID,
- cte_date 是条目的 MYSQL 日期时间戳。
对我来说很难从现在和未来的位置进行测试。我需要找到解决方案,所以我希望有人能告诉我这是否限制为每天一次或每 24 小时一次 - 如果是后者,请为我指明正确的方向。
TIA:)
I'm writing a PHP competition script for a members site that needs to restrict entries to one per day per member. So far I have the following MySQL code:
SELECT ce_id
FROM competition_entries
WHERE ce_c_id = '$c_id'
AND ce_sub_id = '$user_id'
AND cte_date >= SYSDATE() - INTERVAL 1 DAY
- ce_c_id is the competition ID,
- ce_sub_id is the member ID, and
- cte_date is a MYSQL datetime stamp for the entry.
It's hard for me to test from where I am now & I need to find a solution, so I'm hoping someone can tell me whether this is restricting to once-per-day or once-per-24hrs - and point me in the right direction if it's the latter.
TIA :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
未经测试无法确定,但我大胆猜测每 24 小时一次。
请尝试以下操作:
在这里,您清楚地比较了两个日期,一个来自您的字段,另一个来自当前日期是否相等。
Can't be sure without testing, but I'd hazard a guess that it's once every 24h.
Try the following instead:
Here you are clearly comparing two dates, one from your field and the other from the current date for equality.
看起来是 24 小时:
如果您需要“明天”,例如今晚 23:59 过一分钟,请考虑按照简单的
DATE
的解决方案进行咀嚼:通过仅考虑日期而不是时间,您的截止时间实际上将在午夜到期。但请注意,您将受到 MySQL 服务器上的时间的影响,如果应用程序服务器位于不同的计算机上,则该时间可能与应用程序服务器上的时间不同。
Looks like it's 24 hours:
If you need "tomorrow", as in, tonight at one minute past 23:59, consider chomping down things to plain old
DATE
's resolution:By just considering dates instead of times, your cutoff will effectively expire at midnight. Watch out, though -- you'll then be at the mercy of the time on your MySQL server, which might differ from the time on your application server if they are on different machines.
创建由 user_id、competition_id 和日期类型列组成的主键。
检查用户是否已经输入:
Create a primary key composed of the user_id, competition_id and a date type column.
To check if the user has already placed an entry: