I have a table which stores labor data. One of the columns is the amount of hours worked (rthours) on a specific project, another column is the date (labor_date).
I need to grab the sum of all hours worked for each day of the current week and put them into an array to use with a charting script which generates a bar chart.
The chart starts on Monday and ends on Sunday.
I have the following select statement written but it returns wrong values, it also does not take into consideration if there has not been any hours recorded for one of the days.
Any suggestions?
Here is the code:
$sql = "SELECT SUM(rthours) as total FROM data WHERE (WEEK(labor_date) = WEEK(NOW())) AND (user_name = '$user') GROUP BY DAY(labor_date) ORDER BY DAY(labor_date)";
$result = mysqli_query($conn, $sql);
$thours = array();
while ($row = mysqli_fetch_assoc($result)) {
$thours[] = $row["total"];
}
mysqli_close($conn);
?>