E-mailer script running each day (need some conceptual help)
I have a script that works in several steps to e-mail students at a school who are tardy.  The school essentially penalizes students who have 3 and 5 tardies. However, alongside that, there's a total tardy count.  For example, a student can have 16 tardies but their "penalizing" count will be equal to 16 % (mod) 5 (which is 1)


 This is how it works:

**A cron job runs at 3:00 each day checking the following:**
If the amount of times the student is tardy % (mod) 5 = 3, that means they have 3 tardies.  The script then updates a column called "tardyemail" for that particular student to equal 1.

If the amount of times the student is tardy % (mod) 5 = 0, that means they have 5 tardies. The script then updates the tardyemail column to equal 2.
Here's the relevant code:

    if($row['times_tardy'] % 5 == 0) {
    echo $row['fname']." - 5<br />";
    $sql = "UPDATE student SET tardyemail = '2' WHERE rfid = '".$row['StudentID']."'";
    mysql_query($sql) or die (mysql_error());
    }
    if($row['times_tardy'] % 5 == 3) {
    echo $row['fname']." - 3<br />";
    $sql = "UPDATE student SET tardyemail = '1' WHERE rfid = '".$row['StudentID']."'";
    mysql_query($sql) or die (mysql_error());
    }

**A separate cron script runs at 3:30 performing the following:**
Select students who's tardyemail column is equal to 1, and if it's equal to 1, send the template e-mail for 3 tardies out to those students. Then, update the tardyemail column to 0.

Select students who's tardyemail column is equal to 2, and if it's equal to 2, send the template e-mail for 5 tardies out to those students. Then, update the tardyemail column to 0.

Relevant code:

    $sql = "select * from student where tardyemail = '1' AND grade_level > 10";
    $result = mysql_query($sql) or die (mysql_error());
    if(mysql_num_rows($result) > 0) {
    while($row=mysql_fetch_array($result)) {
    
    //Process the mail
    }
    }
    //Update tardyemail to equal 0

    $sql = "select * from student where tardyemail = '2' AND grade_level > 10";
    $result = mysql_query($sql) or die (mysql_error());
    if(mysql_num_rows($result) > 0) {
    while($row=mysql_fetch_array($result)) {
    
    //Process the mail
    } 
    }
    //Update tardyemail to equal 0

The problem with this is the fact that, each day, student's at 3 or 5 tardies are continuously e-mailed because if they don't accrue any more tardies, they remain at 3 and 5.  I need some help figuring out a way to do this to not e-mail them multiple times if they haven't accrued any more tardies.

Thank you so much for any help!
E-mailer script running each day (need some conceptual help)
===

I have a script that works in several steps to e-mail students at a school who are tardy.  The school essentially penalizes students who have 3 and 5 tardies. However, alongside that, there's a total tardy count.  For example, a student can have 16 tardies but their "penalizing" count will be equal to 16 % (mod) 5 (which is 1)


 This is how it works:

**A cron job runs at 3:00 each day checking the following:**
If the amount of times the student is tardy % (mod) 5 = 3, that means they have 3 tardies.  The script then updates a column called "tardyemail" for that particular student to equal 1.

If the amount of times the student is tardy % (mod) 5 = 0, that means they have 5 tardies. The script then updates the tardyemail column to equal 2.
Here's the relevant code:

    if($row['times_tardy'] % 5 == 0) {
    echo $row['fname']." - 5<br />";
    $sql = "UPDATE student SET tardyemail = '2' WHERE rfid = '".$row['StudentID']."'";
    mysql_query($sql) or die (mysql_error());
    }
    if($row['times_tardy'] % 5 == 3) {
    echo $row['fname']." - 3<br />";
    $sql = "UPDATE student SET tardyemail = '1' WHERE rfid = '".$row['StudentID']."'";
    mysql_query($sql) or die (mysql_error());
    }

**A separate cron script runs at 3:30 performing the following:**
Select students who's tardyemail column is equal to 1, and if it's equal to 1, send the template e-mail for 3 tardies out to those students. Then, update the tardyemail column to 0.

Select students who's tardyemail column is equal to 2, and if it's equal to 2, send the template e-mail for 5 tardies out to those students. Then, update the tardyemail column to 0.

Relevant code:

    $sql = "select * from student where tardyemail = '1' AND grade_level > 10";
    $result = mysql_query($sql) or die (mysql_error());
    if(mysql_num_rows($result) > 0) {
    while($row=mysql_fetch_array($result)) {
    
    //Process the mail
    }
    }
    //Update tardyemail to equal 0

    $sql = "select * from student where tardyemail = '2' AND grade_level > 10";
    $result = mysql_query($sql) or die (mysql_error());
    if(mysql_num_rows($result) > 0) {
    while($row=mysql_fetch_array($result)) {
    
    //Process the mail
    } 
    }
    //Update tardyemail to equal 0

The problem with this is the fact that, each day, student's at 3 or 5 tardies are continuously e-mailed because if they don't accrue any more tardies, they remain at 3 and 5.  I need some help figuring out a way to do this to not e-mail them multiple times if they haven't accrued any more tardies.

Thank you so much for any help!