允许用户每小时提交一次他们提交的输入? [英] Allowing users to bump an input they submitted every hour?
问题描述
我希望人们能够碰撞他们在数据库中写入的内容,但同时只允许输入一次在表中。
I want people to be able to "bump" what they've wrote in my database but at the same time only allow the input to be in the table ONCE at a time.
例如:
Jim的代码是5555. Jim输入他的代码,桌子。 34分钟后,他试图再次输入他的代码(因为其他人已经输入他们的代码,从现在到那时),但得到显示错误,让他知道他有26分钟仍然等待。
Jim's code is 5555. Jim enters his code and it shoots to the very bottom of the table. After 34 minutes he tries to enter his code in again (Because various other people have inputted their code between now and then) but gets a display error letting him know he has 26 minutes to wait still.
Joe输入他的代码,并等待一个小时五分钟,并能够将他的代码推回到底部。
Joe inputs his code and waits an hour and five minutes and is able to push his code back to the bottom again.
基本上,我在我的表中显示数据。
Basically, I'm displaying data from the bottom up in my table.
有没有办法轻松做到这一点?
Is there any way to easily do this?
function some_more_custom_content() {
$output="<BR>";
ob_start();
if ($_REQUEST['code'] != "") {
$code = $_REQUEST['code'];
$query="INSERT INTO `fc` (`code`,`datetime`) values ('" . mysql_real_escape_string($code) . "', now())";
$result=mysql_query($query);
$entry['datetime'] = strtotime($entry['datetime']);
while ($fetch_array = mysql_fetch_array($result)) {
$seconds = time() - strtotime($fetch_array["datetime"]);
if ((time() - $entry['datetime']) < 60*60) {
echo ("The code " . htmlentities($code) ." was updated less than an hour ago.");
} else {
echo ("Inserted " . htmlentities($code) ." into the top.");
}
}
?>
我得到语法错误。有什么想法吗?
I get a syntax error. Any idea where it is?
更新:获取错误:
错误:语法错误,意外的$ end
Parse error: syntax error, unexpected $end
推荐答案
然后使用如下的查询:
INSERT INTO CODES (code)
VALUES (555)
ON DUPLICATE KEY UPDATE lastUpdated =
case when NOW() - INTERVAL 5 MINUTE > lastUpdated
then NOW()
else lastUpdated end
只有在超过5分钟的情况下,才会更新lastUpdated字段
this will update the lastUpdated field only in cases when it's older than 5 minutes
这篇关于允许用户每小时提交一次他们提交的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!