Is there a way to only execute part of a WHERE statement using some sort of IF-THEN statement based on data in the database?
The code below displays scheduled tasks for a specific date correctly in most cases, but there is an anomaly. If someone creates a task and then sets a start date before the date they created it, the task won't show up even though it is scheduled on that day.
In this example, we only want to use the create date (i.e. TaskCreated <= '" . $DisplayDateTime . "'") if the start date is not set (i.e. TaskStartDate = '' OR TaskStartDate is NULL') If the TaskStartDate is set, then we want to use that date instead of the create date for the date range.
// Displays tasks that are scheduled on a particular date or marked as "focus"
$sql = "SELECT * FROM Reminders";
$sql = $sql . " " . "WHERE TaskUserID = " . $loggedinuser;
$sql = $sql . " " . "AND ( TaskFocus = 1";
$sql = $sql . " " . "OR ( TaskCreated <= '" . $DisplayDateTime . "'";
$sql = $sql . " " . "AND ( TaskStartDate <= '" . $DisplayDate . "' OR TaskStartDate = '' OR TaskStartDate is NULL )";
$sql = $sql . " " . "AND ( TaskPauseDate <= '" . $DisplayDate . "' OR TaskPauseDate = '' OR TaskPauseDate is NULL )";
$sql = $sql . " " . "AND ( TaskSchedDate >= '" . $DisplayDate . "' AND TaskSchedDate is NOT NULL )" ;
$sql = $sql . " " . "AND ( TaskDueDate <> '" . $DisplayDate . "' OR TaskDueDate = '' OR TaskDueDate is NULL )";
$sql = $sql . " " . ") )";
$sql = $sql . " " . "AND ( TaskPauseDate <= '" . $DisplayDate . "' OR TaskPauseDate = '' OR TaskPauseDate is NULL )";
$sql = $sql . " " . "ORDER BY TaskFocus DESC, TaskPriority ASC, TaskSchedDate ASC, TaskDueDate ASC";
How is the best way to fix that anomaly?
Aucun commentaire:
Enregistrer un commentaire