Guest Posted March 30, 2011 Share Posted March 30, 2011 I have 99% of the code written but I still need a line or two but can't figure it out. Due_Attny is a date field. This code looks at my MySQL database & if the due_attny field is between todays date & the trigger date it will send an email to the $email variable. There is also a field in my MySQL database named a_mail_sent that by default is set to 0 which means an email has not been sent. I need to edit this code so it will look at the a_email_sent field & if the value is 0, it sends the email & updates the a_email_sent field to 1 which means the email has been sent. If the a_mail_sent field has a value of 1, I don't need the email to be sent. Can somoeone help me out with this code? Thanks <?php include('connection.php'); // DB connection // Constants $number_of_days_before = 6; $email = "[email protected]"; $reminder_details = ""; $todays_date = date( "Ymd" ); echo $todays_date; $year = substr($todays_date, 0, 4); $month = substr($todays_date, 4, 2); $date = substr($todays_date, 6, 2); $trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year)); $insertquery = "UPDATE psrinfo SET a_mail_sent=1 WHERE employee='Employee1'"; mysql_query($insertQuery) or die ('Error updating database'); echo $trigger_date; $result = mysql_query( "SELECT a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" ); $nr = mysql_num_rows( $result ); while( $row = mysql_fetch_array( $result ) ) { $reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n"; $reminder_details .= "PACTS Number: ".$row["pacts"]."\n"; $reminder_details .= "Dock: ".$row["dock"]."\n"; $reminder_details .= "Due to Attny: ".$row["due_attny"]."\n\n\n"; } mysql_free_result( $result ); if( !empty( $nr ) ) { // Send reminder email $mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain"; mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232173-php-code-if-statement-help-needed/ Share on other sites More sharing options...
Jnerocorp Posted March 30, 2011 Share Posted March 30, 2011 im not exactly sure if this is what you want but you can try this; <?php include('connection.php'); // DB connection // Constants $number_of_days_before = 6; $email = "[email protected]"; $reminder_details = ""; $todays_date = date( "Ymd" ); echo $todays_date; $year = substr($todays_date, 0, 4); $month = substr($todays_date, 4, 2); $date = substr($todays_date, 6, 2); $trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year)); echo $trigger_date; $result = mysql_query( "SELECT a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" ); $nr = mysql_num_rows( $result ); $sent = mysql_query( "SELECT a_mail_sent FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" ); $rows = mysql_fetch_array( $sent ) while( $row = mysql_fetch_array( $result ) ) { $reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n"; $reminder_details .= "PACTS Number: ".$row["pacts"]."\n"; $reminder_details .= "Dock: ".$row["dock"]."\n"; $reminder_details .= "Due to Attny: ".$row["due_attny"]."\n\n\n"; } mysql_free_result( $result ); if( $rows == "0" ) { // Send reminder email $mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain"; mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader"); mysql_query("UPDATE psrinfo SET a_mail-sent='1' WHERE employee='Employee1'") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232173-php-code-if-statement-help-needed/#findComment-1194346 Share on other sites More sharing options...
Guest Posted March 30, 2011 Share Posted March 30, 2011 Okay, I forgot about my unique FID filed for each record....Please see this code...to see if someone can find my problems...I get the following errors: " Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 16" " Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 18" " Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 28" <?php include('connection.php'); // DB connection // Constants $number_of_days_before = 6; $email = "[email protected]"; $reminder_details = ""; $todays_date = date( "Ymd" ); echo $todays_date; $year = substr($todays_date, 0, 4); $month = substr($todays_date, 4, 2); $date = substr($todays_date, 6, 2); $trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year)); echo $trigger_date; $result = mysql_query( "fid, a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date AND a_mail_sent = 0" ); $nr = mysql_num_rows( $result ); while( $row = mysql_fetch_array( $result ) ) { mysql_query( "UPDATE psrinfo SET a_mail_sent = 1 WHERE fid = " . $row["fid"] . " " ); $reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n"; $reminder_details .= "PACTS Number: ".$row["pacts"]."\n"; $reminder_details .= "Dock: ".$row["dock"]."\n"; $reminder_details .= "Due to Att: ".$row["due_attny"]."\n\n\n"; } mysql_free_result( $result ); if( !empty( $nr ) ) { // Send reminder email $mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain"; mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232173-php-code-if-statement-help-needed/#findComment-1194354 Share on other sites More sharing options...
Guest Posted March 30, 2011 Share Posted March 30, 2011 I forgot to add the SELECT statement in the posr but it is there in the code & still getting the same errors Quote Link to comment https://forums.phpfreaks.com/topic/232173-php-code-if-statement-help-needed/#findComment-1194360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.