我一直困扰着试图解决这个问题,因为我已经做了很长时间的mysql调用。
我想按行检查" user_id" ,"条目"和"时间"并查看是否已经过了至少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分钟进行一次测验 thx提前
答案 0 :(得分:0)
$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!! ";
}