如何让PHP每个月删除一个用户限制
我有这个代码来增加用户的搜索限制,如果他们达到了限制
$search = $db->prepare("SELECT `searched` FROM `search` WHERE `user_id` =:user_id");
$search->bindValue(':user_id', $vbulletin->userinfo['userid'], PDO::PARAM_INT);
$search->execute();
$result = $search->fetch(PDO::FETCH_ASSOC);
if ($result['searched'] >= 100){
exit('You have reached your search limit for this month.<br>');
}
$addsearch = $db->prepare("UPDATE `evomap`.`search` SET `searched` = :searched + 1 WHERE `search`.`id` =:user_id;");
$addsearch->bindValue(':user_id', $vbulletin->userinfo['userid'], PDO::PARAM_INT);
$addsearch->bindValue(':searched', $result['searched'], PDO::PARAM_STR);
$addsearch->execute();
/* page i want to execute if user has no reached limit */
您最好有一个包含月份时间戳的列,设置为日期,当用户搜索次数达到100次时,然后检查当前月份=时间戳。但是你也可以尝试MySQL事件。比如:
DELIMITER $$
CREATE EVENT search_removal
ON SCHEDULE EVERY MONTH
DO
BEGIN
UPDATE search SET searched = 0;
END;
$$;