标题很奇怪,是的。(我是挪威人)
好的,我正在为我的新项目制作一个计数器/计时器,它的作用是当用户执行操作时,他/她必须等待 100 秒才能再次执行此操作。但是,如何将时间戳(保存在 mysql db 中)再次放入 PHP 代码中,并检查自上次用户检查重试以来的时间。
我的一些代码(来自脚本):
// Waiting for time to go?
$sql = mysql_query("SELECT * FROM `crimes` WHERE user_id = '".$_SESSION["id"]."'");
$num = mysql_num_rows($sql);
$row = mysql_fetch_array($sql);
if($num == 1){ //Waiting
$time_now = date("H:i:s", strtotime("+100 seconds")); // This is where Im stuck, how to get that timestamp from mysql with 100 secs added?
$time_to_check = date("H:i:s", $row["time"]); // The time the action was done.
// This is where the code is going to check how long time since user visited.
} else {
}
所以我要求的是我需要一个包含来自 mysql 的数据并添加 100 秒的 var,如何?:)
这有效:
$sql2 = mysql_query("SELECT UNIX_TIMESTAMP(time) AS time FROM `crimes` WHERE user_id = '".$_SESSION["id"]."'");
$row2 = mysql_fetch_array($sql2);
$seconds_ago = time() - $row2['time'];
$time_now = date("H:i:s", $seconds_ago + 100);