简体   繁体   English

如何允许用户每天不连续24小时投票一次?

[英]How to allow user to vote once per day not for last 24hrs?

I am trying to create function that allow users to vote only once in a day. 我正在尝试创建仅允许用户每天投票一次的功能。 For this I have created ratingTimestamp field in table in which I am inserting the current timestamp value at the voting time. 为此,我在表中创建了ratingTimestamp字段,我将在投票时插入当前时间戳值。

And for validating the users that he can vote only once per day. 为了验证用户他每天只能投票一次。 I am using this MySQL query: 我正在使用此MySQL查询:

SELECT count( * ) AS votecount
FROM ratings AS e
WHERE e.userId =5
AND e.ratingTimestamp >= NOW( ) - INTERVAL 1
DAY 

The problem is that this query giving me votecount on 24hrs basis but I want it on the basis of date only. 问题是此查询给我24小时的votecount ,但是我只希望基于日期。

Like if user voted on 12-03-2014 11:59:00 AM and again he tried for voting at 13-03-2014 4:00PM he can vote but with using the above query it is not possible because it is giving me vote count 1 for this case because it is counting the last 24hrs from 4:00PM. 就像用户在12-03-2014 11:59:00 AM上投票一样,他又尝试在13-03-2014 4:00 PM上投票,他可以投票,但是使用上面的查询是不可能的,因为它给了我投票权在这种情况下,请计算1,因为它是从4:00 PM开始计算最后24小时。

I think You should use something like this: 我认为您应该使用这样的东西:

$sql="SELECT count( * ) AS votecount FROM ratings WHERE DATE(e.ratingTimestamp) = CURDATE()";

OR you can try through PHP 或者您可以尝试通过PHP

$sql="SELECT count( * ) AS votecount FROM ratings WHERE e.ratingTimestamp >= '".strtotime("today")."' AND e.ratingTimestamp < '".strtotime("tommorow")";

OR alternatively look into this link 或者,也可以查看此链接

Retrieve records by current date from MySQL 从MySQL按当前日期检索记录

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

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