我正在试着在时间戳的时候发送自动电子邮件。我在数据库中有一组unix时间戳。我把它们拉出来,然后试着把它们相互比较。在结尾处断开的部分。foreach没有返回正确的eblast id,我想我减去unix时间戳是正确的,但是我不确定。我希望if语句仅在数据库中的时间戳比now时间戳早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';
}
};发布于 2010-11-27 09:15:18
假设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);
...发布于 2010-11-27 08:55:00
为什么不修改第一个SQL查询,只选择时间戳列小于当前时间减去15分钟秒数的记录呢?
https://stackoverflow.com/questions/4289334
复制相似问题