我正在开发一个预订系统,允许人们72小时(3天)通过点击链接确认他们的注册。如果注册尚未确认,我希望在48小时(2天)后发送提醒电子邮件。如果在72小时(3天)后未得到确认,则将从数据库中删除注册。
但是,我不知道如何处理if / else语句。我的逻辑在我今天死了。 有人能给我一个正确的if和else语句吗?非常感谢!
<?php include "config.php"; ?>
<?php
// Connect to database
$query = mysqli_query($con,"SELECT * FROM reservations WHERE reserved='yes' AND confirmed='no'");
$row = mysqli_fetch_array($query);
// set reservation time
$datetime = $row['datetime'];
$datetime -> modify('+3 days');
$now = date("Y-m-d H:i:s");
foreach $query as $row {
if ($datetime > $now) {
//it still has time. sent reminder if less than 24 hours left.
} else {
//time has passed, set registration inactive.
}
}
?>
答案 0 :(得分:0)
为什么不在数据库中进行日期比较?
SELECT *
FROM reservations
WHERE reserved='yes' AND confirmed='no' AND
datetime > now() - interval 3 day AND datetime <= now() - interval 2 day;
这将仅返回您要联系的行,因此您不需要在应用程序端使用其他逻辑(对于datetime
)。