我想在第一次更新 10 分钟后更新我的值
例如,我发送了这个请求:
UPDATE client set lockclient = 1 WHERE id = 100
我想在 10 分钟后发送另一个请求,如下所示:
UPDATE client set lockclient = 0 WHERE id = 100
我在谷歌上找到了这个例子:
DELIMITER $$
CREATE EVENT deactivation
ON SCHEDULE EVERY 10 MINUTE STARTS CURRENT_TIMESTAMP
DO
BEGIN
UPDATE tbl SET tbl.active = FALSE WHERE id =10
END;
$$;
但我只想在前 10 分钟更新一次,而不是每 10 分钟更新一次。 我可以用 php、mysql 或 javascript 做到这一点吗?
最佳答案
您可以像这样使用 setTimeout()
javascript 函数尝试 Ajax:
<div id="id_test"></div>
<SCRIPT language=javascript>
var update1 = false
update2 = false;
function run_ajax(lockclient){
// write your call ajax function with lockclient parameter
// this is an example to test the principle
var dt=new Date()
document.getElementById("id_test").innerHTML = dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds() + "<br>lockclient =" + lockclient;
}
function Timer() {
// if you have already called 2 times the server, you leave
if (update2 && update1)
return;
// if you have already called 1 time the server, you call it a second time with '0' as lockclient parameter
if (!update2 && update1){
update2 = true;
run_ajax(0)
}
// If you did not call the server, you call it a first time with '1' as lockclient parameter
if (!update1){
update1 = true;
run_ajax(1)
}
//setTimeout("Timer()",600000); -> 600000 = 10 minutes
setTimeout("Timer()",2000); // 2s to test
}
Timer();
</SCRIPT>
关于javascript - 如何在第一次更新 'X' 分钟后更改字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29799512/