0

如何让 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 */
4

1 回答 1

1

您最好有一个带有月份时间戳的列,设置为日期,当用户达到 100 次搜索时,然后检查当前月份是否!= 时间戳。但是您也可以尝试 MySQL 事件。就像是:

  DELIMITER $$
  CREATE EVENT search_removal
    ON SCHEDULE EVERY MONTH
    DO
      BEGIN
        UPDATE search SET searched = 0;
      END;
  $$;
于 2013-03-11T00:22:33.507 回答