This topic is locked
[SOLVED]

 When expiration date is coming, email me!

2/29/2012 3:19:50 AM
PHPRunner General questions
S
sickacid author

Hi, I want to check a table with date, when date diff is < of 31 days the system must email me something. But i've some problem with Mysql query, MIN is supported? I've put this code in after login succesfull.
(data_scadenza means expiration date and is the field in the db)
global $conn;

$str = "select MIN(data_scadenza), Id_scadenza from tabella_scadenze where scadenza_gestita=0";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$ID = $data["Id_scadenza"];

$SC = $data["data_scadenza"];

//echo "INFO: ",$ID, " ", $SC;
$diff = abs(strtotime($ID)) - abs(strtotime(now())) ;

//echo "INFO: ", $diff, " ", strtotime($data["data_scadenza"]), " ",strtotime(now());

$years = floor($diff / (365606024));

$months = floor(($diff - $years
365606024) / (30606024));

$days = floor(($diff - $years 365606024 - $months30606024)/ (606024));

$email="info@sistemapolare.it";

$from="info@sistemapolare.it";

$msg= "ATTENZIONE!!\n\nCI SONO SCADENZE IN CORSO nello scadenziario\nSistema Polare" + $days;

$subject="Avviso scadenze MORE+";
//send simple email

if ($days<31)

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

else return true;

if(!$ret["mailed"])

echo $ret["message"];

C
cgphp 2/29/2012
$diff = abs(strtotime($ID)) - abs(strtotime(now())) ;


Is it correct the above statement?

S
sickacid author 2/29/2012


$diff = abs(strtotime($ID)) - abs(strtotime(now())) ;


Is it correct the above statement?


Hi, i've recicled if from another code <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64649&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' /> but, I haven't try it again, I don't know if it really works correctly ,but my problem is in the sql query. Because i can't obtain che MIN value

C
cgphp 2/29/2012

Try this version:

global $conn;

$str = "select MIN(data_scadenza) as scadenza, Id_scadenza from tabella_scadenze where scadenza_gestita=0";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$ID = $data["Id_scadenza"];

$SC = $data["scadenza"];

//echo "INFO: ",$ID, " ", $SC;
$diff = abs(strtotime($SC) - strtotime(now()));

//echo "INFO: ", $diff, " ", strtotime($data["data_scadenza"]), " ",strtotime(now());

$years = floor($diff / (365*60*60*24));

$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));

$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

$email="info@sistemapolare.it";

$from="info@sistemapolare.it";

$msg= "ATTENZIONE!!\n\nCI SONO SCADENZE IN CORSO nello scadenziario\nSistema Polare" + $days;

$subject="Avviso scadenze MORE+";
//send simple email

if ($days<31)

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

else return true;

if(!$ret["mailed"])

echo $ret["message"];
S
sickacid author 3/1/2012

global $conn;

$str = "select MIN(data_scadenza) as scadenza, Id_scadenza from tabella_scadenze where scadenza_gestita=0";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$ID = $data["Id_scadenza"];

$SC = $data["scadenza"];

//echo "INFO: ",$ID, " ", $SC;
Hi, it's strange, but with this query i get the MIN value of Id_scadenza where scadenza_gestita=0, and not the MIN value of data_scadenza with scadenza_gestita=0
With this query, in this case I get the line:
ID:69 DATE 07/07/2012 SCADENZA_GESTITA 0
BUT i must GET THE FOLLOW LINE:
ID:101 DATE 04/04/2012 SCADENZA_GESTITA 0
But i've try to build this query with open office and alwais i get the ID_line 69! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64666&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> I'm on Mysql 5.1.37. any suggestions?

S
sickacid author 3/5/2012

I've solved with this query <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64740&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
$str = "select Id_scadenza as ids, MIN(data_scadenza) as scadenza from tabella_scadenze where scadenza_gestita=0 group by Id_scadenza ORDER BY MIN( data_scadenza )";