I have a database for clock in clock out system The table structure consists of time_id, user_id, weekNo, ClockYear, EntryDate, StartTime, EndTime and updated_at
basically the startTime is clock in and EndTime is clocked out time what im trying to do is run a query to get me the total worked hours by a user on a sepcific date total instead of total hours worked per individual entry. so currently i have the following query:
SELECT CONCAT(users.first_name," ",users.last_name) AS theUser,
time_logs.*, TIMEDIFF(endTime,startTime) AS totTime FROM time_logs
LEFT JOIN users ON time_logs.user_id = users.user_id WHERE
time_logs.entryDate >= "2016-08-17" AND time_logs.entryDate <= "2016-08-25" order by user_id ASC
and this returns the results as
[0] => Array
(
[theUser] => Sam Johnson
[timeId] => 14
[user_id] => 1
[weekNo] => 34
[clockYear] => 2016
[entryDate] => 2016-08-23
[startTime] => 2016-08-23 16:16:30
[endTime] => 2016-08-23 17:36:14
[updated_at] => 2016-08-23 17:36:14
[totTime] => 01:19:44
)
[1] => Array
(
[theUser] => Sam Johnson
[timeId] => 15
[user_id] => 1
[weekNo] => 34
[clockYear] => 2016
[entryDate] => 2016-08-24
[startTime] => 2016-08-24 01:00:00
[endTime] => 2016-08-24 05:15:00
[updated_at] =>
[totTime] => 04:15:00
)
[3] => Array
(
[theUser] => Bob Doe
[timeId] => 19
[user_id] => 2
[weekNo] => 34
[clockYear] => 2016
[entryDate] => 2016-08-24
[startTime] => 2016-08-24 10:00:00
[endTime] => 2016-08-24 13:15:00
[updated_at] =>
[totTime] => 03:15:00
)
As you can see it gives total time for that specific entry but what i want to get is just one entry for each user with the total time totalled up for all entries by that user on that day combined so for user 1
[0] => Array
(
[theUser] => Sam Johnson
[user_id] => 1
[weekNo] => 34
[clockYear] => 2016
[entryDate] => 2016-08-23
[totTime] => 05:34:44
)
can anyone help with this not sure if i can do it using a query