以下是我的email.php。代码运行良好,直到我尝试计算笔记本电脑保修到期的行数。行数可以打印出来,但不包含代码中所述的每台笔记本电脑的说明。我可以知道如何修复此代码吗?
编辑:
例如,电子邮件的内容将如下所示:
亲爱的IT Infra,
总共125台笔记本电脑将在不到45天的时间内到期。
状态:贷款
笔记本电脑序列号:R8VMGFH
过期日期:2013-01-17
等......(笔记本电脑的另外124个描述)
它应该显示所有这些,但现在不显示。
Email.php:
<?php
// ======== get database data =======
include 'MasConnectDB.php';
$count = 0;
$sql = "SELECT Lap_Status, Lap_SN, Lap_War_Expiry FROM laptop WHERE
Lap_War_Expiry!='0000-00-00' AND Lap_War_Expiry!='' ";
$result = mysql_query( $sql ) or die('Query failed. ' . mysql_error() );
while( $row = mysql_fetch_array( $result ) ) {
$Lap_Status = $row['Lap_Status'];
$Lap_SN = $row['Lap_SN'];
$Lap_War_Expiry = $row['Lap_War_Expiry'];
date_default_timezone_set("Asia/Kuala_Lumpur");
$today_date = date('Y-m-d');
$expiry_date = $Lap_War_Expiry;
$timestamp = strtotime($expiry_date);
$warning_days = 45;
$seconds_diff = $warning_days * 24 * 3600;
$warning_timestamp = $timestamp - $seconds_diff;
$warning_date = date('Y-m-d', $warning_timestamp);
if ( $today_date >= $warning_date ) {
$message = $message." <div style='margin:30px 0px;'>
Status : $Lap_Status<br />
Laptop serial number: $Lap_SN<br />
Date of expired:$Lap_War_Expiry <br /></div>";
$count++;
}
}
$message ="Dear IT Infra,<br/><br /> Total $count of laptop are going to expire in
less than 45 days.<br /><br />";
require_once('class.phpmailer.php');
//Email goes here
答案 0 :(得分:0)
您可以使用mysql datediff函数来短路代码。
SELECT Lap_Status, Lap_SN, Lap_War_Expiry
FROM laptop
WHERE Lap_War_Expiry = DATE(DATE_ADD(NOW(), INTERVAL 45 DAY))