gpt4 book ai didi

php - mysql Unix时间戳检查是否已过去2小时

转载 作者:行者123 更新时间:2023-11-29 19:28:45 27 4
gpt4 key购买 nike

我一直在试图解决这个问题,自从我完成 mysql 调用以来已经很长时间了。

我想按行“user_id”、“entry”和“time”进行检查,看看是否已经过去了至少 30 分钟以及是否没有提醒用户

到目前为止我的代码是:

$chkquery = "SELECT * FROM wpqi_myCRED_log WHERE entry='quiz' AND user_id='1' AND time < unix_timestamp() - 1800";

如果已经超过 30 分钟,那么可能是这样的

    if( $time_diff >= 1800) {
echo "Yay! It has been 30 minutes!";

} else {
$remaining = (1800 - $time_diff );
echo "Wait! Its not been 30 minutes\n";
echo "please come back in ".date ( "i:s" , $remaining)." minutes";
}

我不希望他们每 30 分钟做一次测验提前谢谢

最佳答案

好吧,这就是我最终所做的,它可能很乱,可以清理,但似乎正在工作,我洗耳恭听任何建议!

$user_id ="1";
$refType="completing_quiz_full";

//Minutes allowed between plays
$minutesAllowed = 120;

// take minutes allowed and subract
$get2hour = time() - ($minutesAllowed * 60);

$chkquery = "SELECT * FROM wpqi_myCRED_log WHERE ref='$refType' AND user_id='$user_id' AND time >= $get2hour order by time desc limit 1";
$chk = mysql_query($chkquery) or die($chkquery."<br/><br/>".mysql_error());
$num_rows = mysql_num_rows($chk);

//echo "this many rows meet that criteria is : ". $num_rows. "<br>" ;

if ($num_rows > 0) {
while($row = mysql_fetch_array($chk, MYSQL_ASSOC)){
$entry = $row['entry'];
$coin = str_replace("%plural%","Burst",$entry);
echo "<br> You already received ". $coin. "<br>" ;

// get time from Table
$then =$row['time'];
$played = date('h:i:s A', $then);

//Get the current timestamp.
$now = time();

//Calculate the difference.
$difference = $now - $then;

//Convert to nearest minute
$minutes = floor($difference / 60);

//now subtract minutes we allowed
$timeLeft = $minutesAllowed - $minutes;

echo "You Have ". $timeLeft. " Minutes till you can play again<br> You Last Played at ". $played. "<BR>";

}

} Else {

echo " now we can show your the content cause its been over 2 hours!! ";

}

关于php - mysql Unix时间戳检查是否已过去2小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41949835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com