I have a script that checks the database for upcoming classes and sends out a reminder link 3 days before (via cron job ran daily). For some reason, randomly students that have reservations for the course get 3 emails sent to them...not 2, not 4, 3! It's actually pretty random, not all the students who have a reservation linked to the course get 3 only a few. The rest only get 1 like they are supposed to... Any help is much appreciated!
PHP Code:$class_date = date('Y-m-d', strtotime($today.'+3 day'));
$a=mysqli_query($dbc, "SELECT * FROM course WHERE date='$class_date'");
while($class=mysqli_fetch_array($a)){
$b=mysqli_query($dbc, "SELECT * FROM reservation WHERE course='".$class['id']."' ");
while($res=mysqli_fetch_array($b)){
$to=getStudentName($res['student']).' <'.getStudentEmail($res['student']).'>';
$subject="Class Reminder";
$query="SELECT * FROM course WHERE id='".$res['course']."'";
$result=mysqli_query($dbc, $query);
$c=mysqli_fetch_array($result);
//message to send
$mes= "Class is in 3 days! This is a reminder email";
sendEmail("CSTC <training@calsecurity.us>", $to, $subject, $mes);
//insert student notes
$notes='Automated confirmation email sent by TCM SYSTEM @'.date('H:i');
$date=date('Y-m-d');
mysqli_query($dbc, "INSERT INTO student_notes(student, admin, notes, timestamp) VALUES('".$res['student']."', '1', '$notes', '$date')");
}
}
Am i mising something here? I have a feeling the while loop isn't the most reliable...



Reply With Quote
Bookmarks