Ok, So I’m writing a task organizer script and I’m having some issues with marking the subtasks as complete or not complete.. my code is as follows…
if($_POST['finished']){ // $_POST['finished'] is an html array of check boxes
$subtask = Subtask::find_all_by_task_id($task->id);
foreach($subtask as $stask){
foreach($_POST['finished'] as $fin){
if($stask->id == $fin){
$stask->finished_at = date('Y-m-d H:i:s', time());
$stask->save();
} elseif($stask->id != $fin){
$stask->finished_at = "";
$stask->save();
}
}
}
} else { // This works as expected when un-checking all checkboxes
$subtask = Subtask::find_all_by_task_id($task->id);
foreach($subtask as $stask){
if($stask->finished_at != null){
$stask->finished_at = null;
$stask->save();
}
}
}
My problem I believe is the if statement is rolling over both values(there are only two subtasks right this minute) when it gets to the last values all other $fin does not equal $stask->id anymore so those get set back to null in the DB hence making it SEEM as though they’re never updated..How can I fix this whats the best route to tackle this if statement..I’ve tried a few variations but to no avail.
Ok, So a simple workaround/solution was this..