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

mysql Unix timestamp check if 2 hours elasped

我一直在努力解决这个问题,我已经很长时间没打过 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!! "; 

      }