-1

嘿伙计们,可以说我有一个成员放了 20 天。因此,如果有会员 20 天后,可以说没有登录,它将改变那里的状态。但仅基于在 MySQL 数据库中写入的状态更改日期为year-month-day. 因此,如果他的状态更改日期已经过去了 20 天,那么他的状态就会发生变化。

如果您能帮助我了解如何执行此操作,我将不胜感激!

大卫

更新:

代码:

$newStatus = "Non-Active - Driver Chose Non-Compliance";

    $sql = "SELECT username,ATF FROM members WHERE username = 'test'";
    $getcsvuser = $DBH->prepare($sql);
    $getcsvuser->execute();
    while($row = $getcsvuser->fetch(PDO::FETCH_ASSOC)){

        $memusername = $row['username'];
        $memATF = $row['ATF'];
        if ($memATF != 0 || $memATF != "0")
        {
        $tsql = "SELECT username,status,memberview ,statuschangedate FROM csvdata WHERE memberview =:user";
        $tgetcsvuser = $DBH->prepare($tsql);
        $tgetcsvuser->execute(array(':user' => $memusername));
        while($trow = $tgetcsvuser->fetch(PDO::FETCH_ASSOC)){

            $csvstatus = $trow['status'];
            $csvusername = $trow['username'];
            $csvdate = $trow['statuschangedate'];

            if($csvstatus == "Open" || $csvstatus == "Enrolled - Policyholder Follow-Up Required" || $csvstatus == "Enrolled - Employee Follow-Up Required" || $csvstatus == "Non-Active - Insurance Cancelled" || $csvstatus == "Non-Active, Unable to Monitor - Incidental Business use Exclusion" || $csvstatus == "Non-Active - Employee Not Covered Under Listed Policy" || $csvstatus == "Non-Active - PolicyHolder Cancelled Additional Interest")
            {

                $newsql = "UPDATE csvdata SET status = :newstatus WHERE statuschangedate < NOW() - INTERVAL :atf DAY AND username =:mem";
                $newgetcsvuser = $DBH->prepare($newsql);
                $newgetcsvuser->execute(array(':newstatus' => $newStatus, ':atf' => $memATF, ':mem' => $csvusername));
                while($rrow = $newgetcsvuser->fetch(PDO::FETCH_ASSOC)){
                    echo "working";
                }
            }

        }
        }

    }
4

3 回答 3

2

它可以是两件事的组合:

mysql 更新要更改的用户:

update
  members
set
  status = 'foo'
where
  status_change_date < NOW() - INTERVAL 20 DAY

第二部分将是一个 cron 作业,每天运行该查询。

于 2013-02-14T22:36:35.190 回答
1

那个怎么样:

UPDATE tablename
SET inactive = 1
WHERE date_field < DATE_SUB(NOW(), INTERVAL 20 DAY)

cronjob您可以每晚运行一次此查询。

所以这可以在不使用 PHP 逻辑的情况下完成,除了执行这个 SQL 查询。

于 2013-02-14T22:36:45.777 回答
1

我没有对此进行测试,但它应该很接近。

//$dbVal = $row["databaseColumn"];
$dbVal = "2013-01-24";  //For example
$now = Date();

$diff = abs($now - strtotime($dbVal));

$daysSince = floor(($diff/(60*60*24));
if ($daysSince >20){
    //Set status in DB;
}

合并@popnoodles 解决方案:

//$dbVal = $row["databaseColumn"];
$dbVal = "2013-01-24";  //For example
$expireTime = 20;

$diff = strtotime($dbVal) - strtotime("today - $expireTime days");
if ($diff < 0 ){
    //Set status in DB;
}
于 2013-02-14T22:37:30.747 回答