I have a php loop that is meant to query a database and send out email to groups of people. In this example, it returns two rows.
The problem is that it includes the results of the first run in the 2nd run.
My Code:
$query = mysql_query("SELECT * FROM tasks WHERE DATE(`show_date`) = ( CURDATE() - INTERVAL 1 DAY ) AND drive_folder_empty = 'empty' AND drive_folder IS NOT NULL;");
while ($row = mysql_fetch_assoc($query)){
if (!empty($row['robert'])){$robert_email = "robert email"; $robert_phone = "robert phone";}
if (!empty($row['duncan'])){$duncan_email = "duncan email"; $duncan_phone = "duncan phone";}
if (!empty($row['mike'])){$mike_email = "mike email"; $mike_phone = "mike phone";}
if (!empty($row['james'])){$james_email = "james email"; $james_phone = "james phone";}
$email_array = array($robert_email, $duncan_email, $mike_email, $james_email);
$filtered_email = array_filter($email_array);
print_r($filtered_email);
$mail_to = implode(', ', $filtered_email);
$phone_array = array($robert_phone, $duncan_phone, $mike_phone, $james_phone);
$filtered_phone = array_filter($phone_array);
$cc = implode(', ', $filtered_phone);
if (!empty($mail_to))
sendEmail($mail_to, $drive_url, $date_of_show, $cc);
}
}
Results From Database:
ID EID drive_folder drive_folder_name drive_folder_empty duncan robert mike james partners_name completed_form all_forms_in priority ask_for_review blog_status bloggers_email todays_date show_date
20 2457 drive url drive name empty Duncan Robert NULL NULL NULL n n NULL NULL NULL NULL 2017-04-24 2017-04-29
21 2468 drive url drive name empty NULL NULL Mike James NULL n n NULL NULL NULL NULL 2017-04-24 2017-04-29
What Happens:
Array
(
[0] => robert email
[1] => duncan email
)
Array
(
[0] => robert email
[1] => duncan email
[2] => mike email
[3] => james email
)
What I Want To Happen
Array
(
[0] => robert email
[1] => duncan email
)
Array
(
[0] => mike email
[1] => james email
)
Why is it retaining the previous values on the 2nd run?