我正在尝试创建一个人们可以提交内容的网站。用户可以查看当月已提交的次数以及仍可以完成的提交次数。我想要的是,当本月达到提交限制时,网站应该阻止本月的任何提交。我怎么知道它只会阻止这几个月的未来提交?我仍然希望人们能够在其他月份提交。
date_default_timezone_set('UTC');
$currentDate = date("m");
$currentDate2 = date("F");
$maxSubmissions = '7';
$monthChecker[] = array();
$monthQuery = "SELECT * FROM submissions
WHERE MONTH(dateRelease)= '$currentDate' ";
if($result = $db->query($monthQuery)) {
//Count amount of reservations of current month and show them
$teller = $result->num_rows;
if($teller == $maxSubmissions){
//The limit has been reached
$monthChecker['limit'] = "Het reserveringslimiet voor " . $currentDate . " is al bereikt. ";
if($teller > $maxSubmissions){
// I think that i should write something here, but I have no idea what...
}
} else{
// the limit has not yet been reacherd
$monthChecker['nolimit'] = "Er is in " . $currentDate2 . " al ".$teller." keer gereserveerd";
}
} else {
//if error
die("mysqli error: " . mysqli_error($db));
}
答案 0 :(得分:0)
如果您尝试将每个用户限制为每月仅提交7次,则需要减少该userId返回的设置。例如,如果您的提交表还包含userId,您可以添加以下和子句:
$monthQuery = "SELECT * FROM submissions
WHERE MONTH(dateRelease)= '$currentDate'
AND userId = $userId";
如果此数据是关系数据,则可能需要使用联接。
此处您可能还有次要问题,因为上述内容将专门针对MONTH。如果提交表上没有清理机制,您最终可能会提前影响当前年度的提交。