gpt4 book ai didi

php - 时间数组找到一个比设定时间早 15 分钟的时间

转载 作者:行者123 更新时间:2023-11-29 14:57:16 25 4
gpt4 key购买 nike

我正在尝试按时间戳发送自动电子邮件。我在数据库中有一组 unix 时间戳。我把它们拉出来,然后尝试将它们相互比较。最后断裂的部分。 foreach 不会返回正确的 eblast id。我认为我正确地减去了 unix 时间戳,但我不确定。我希望 if 语句仅在数据库的时间戳早于当前时间戳 15 分钟时触发。我只希望它在数据库时间戳 15 分钟之前的任何时间触发。如果它在数据库的时间戳之后,则不执行任何操作。希望这是有道理的。

session_start();
date_default_timezone_set('America/Chicago');

error_reporting(E_ALL);
include 'DB.php';

$timestamp = time();

echo 'Timestamp:';
echo $timestamp;
echo '------';

$drop_dead = mysql_query("SELECT due_date, ID FROM eblasts") or die(mysql_error());

while ($row = mysql_fetch_array($drop_dead, MYSQL_NUM)) {
$final_email_id[$row[1]] = $row[0];
};

//this is the ID's of eblasts that need an email sent based on their drop_dead NOT on warning1, warning2 and due_date.
print_r($final_email_id);

foreach($final_email_id as $key => $value) {
$query = mysql_query("SELECT warning_1 FROM eblasts WHERE ID = '$key'") or die(mysql_error());
$find_warning_1 = mysql_fetch_row($query);
$warning_1[$key] = $find_warning_1[0];
}
//this is the warning_1 numbers where the ID's of the array are the ID's of the eblast.
print_r($warning_1);

foreach($final_email_id as $key => $value) {
$query = mysql_query("SELECT warning_2 FROM eblasts WHERE ID = '$key'") or die(mysql_error());
$find_warning_2 = mysql_fetch_row($query);
$warning_2[$key] = $find_warning_2[0];
}

//this is the warning_2 numbers where the ID's of the array are the ID's of the eblast.
print_r($warning_2);

foreach($final_email_id as $key => $value) {
$query = mysql_query("SELECT due_date FROM eblasts WHERE ID = '$key'") or die(mysql_error());
$find_due_date = mysql_fetch_row($query);
$due_date[$key] = $find_due_date[0];
}

//this is the due date numbers where the ID's of the array are the ID's of the eblast.
print_r($due_date);

//Add 900 because its 15 minutes in seconds ...
$run_time = $timestamp + 900;

foreach($warning_1 as $key => $value){
$diff_time = $run_time - $warning_1[$key];
echo '-----';
echo $diff_time;
echo '-----';
if($diff_time < 900 && $diff_time > 0){
echo 'different';
echo $diff_time;
$_SESSION['eblast_id'] = $key;
include 'warning_1.php';
}
};

最佳答案

假设 warning_x 字段也是时间戳,这应该可以解决问题:

$timestamp = time();

$query = sprintf(
'SELECT id, warning_1' .
' FROM eblast' .
' WHERE (UNIX_TIMESTAMP(warning_1) - %u) BETWEEN 1 AND 899',
$timestamp
);

while ($row = mysql_fetch_array($query, MYSQL_NUM)) {
$ids[$row[0]] = $row[1];
};

var_dump($ids);
...

关于php - 时间数组找到一个比设定时间早 15 分钟的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4289334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com