I want to send the overdue tasks that are assigned to a specific employee as an email summary. It is possible that multiple todos are assigned to the same employee. So multiple todos can be assigned to the same employee AND are overdue. That's where the problem starts...
So what I did, is grabbing all the overdue tasks from the database and then I grabbed the assigned employees to the tasks. I created an array that consists of the todoID
, the employeeID
and the employeeEmail
. Now, is there a better way to do this and if not, how can I group the rows by email address?
The end result should be an array that shows every overdue todo that's assigned to one employee.
// Get all Todos that are not archived
$sql = "SELECT * FROM todo WHERE archiv = 0";
$abfrage = $db->prepare($sql);
$abfrage->execute();
$overdue_array = array();
// Now we get everything that's overdue from the Database
while ($row = $abfrage->fetch()) {
if ($row["status"] !== 3) {
if ($row["archiv"] !== 1) {
if ($row["durchfuehrung"]) {
if (strtotime($row["durchfuehrung"]) < strtotime(date("Y-m-d"))) {
// Here we now get the email from the assiged employee to the todo
$sql2 = "SELECT email FROM mitarbeiter WHERE mitarbeiterID = :mitarbeiterFID";
$abfrage2 = $db->prepare($sql2);
$abfrage2->bindParam("mitarbeiterFID", $row["mitarbeiterFID"]);
$abfrage2->execute();
while ($row2 = $abfrage2->fetch()) {
$overdue_array[] = array("todoID" => $row["todoID"], "mitarbeiterID" => $row["mitarbeiterFID"], "mitarbeiterEmail" => $row2["email"]);
}
}
}
}
}
The result is the following: