i want to send the mail , when product got expire from before and ondate and after day, in php i was used datediff mysql function with php, but if product expire date comes like 31-1-2012 , the differ value is not suit for my coding , plz help how to solve it ,
This is my coding
<?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'];
}
}
}
}
}
?>