gpt4 book ai didi

产品过期时发送 PHP 邮件

转载 作者:行者123 更新时间:2023-11-29 14:35:49 26 4
gpt4 key购买 nike

我想发送邮件,当产品从之前、日期和之后过期时,在 php 中,我在 php 中使用了 datediff mysql 函数,但如果产品过期日期类似于 31-1-2012 ,则不同值是不适合我的编码,请帮助如何解决它,这是我的编码

<?php

$sql = mysql_query("SELECT * FROM supplier_product_det");
$results = mysql_num_rows($sql);
//echo '<script>alert("'.$results.'")</script>';
if ($results > 0)
{

for($i=0;$i<$results;$i++)
{
while($rows = mysql_fetch_array($sql))
{
/* print_r($rows['expired_on']);?><br /> <?*/
$exdate = $rows['expired_on'];
$curdate = date('Y-m-d');
$datedif = mysql_query("select datediff('".$curdate."','".$exdate."')");
while( $date = mysql_fetch_array($datedif) )
{
//echo $date['0'];
//echo $rows['pro_code'];
if (($date['0'])== 1)
{

if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product Expired
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone@bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}


//echo $rows['supplier'];

}
if (($date['0'])== 0)
{
if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product Expired
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone@bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}


//echo $rows['supplier'];

}
if (($date['0'])== -1)
{
if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product will Expire Today
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone@bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}


//echo $rows['supplier'];

}
}

}

}

}
?>

最佳答案

按如下方式编写第二个选择查询

SELECT DATEDIFF($exdate, CURRENT_DATE) as diff;

此外,无需编写单独的选择查询,您可以在第一个查询本身中获得相同的列

SELECT column1, column2, column3, DATEDIFF(expired_on, CURRENT_DATE) as diff
FROM supplier_product_det

您可能需要更改 expired_on 和 CURRENT_DATE 的位置才能获得正确的差异值

关于产品过期时发送 PHP 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9076663/

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