in my php mysql report, I extract data from mysql table with below code. everything is working fine, but i unable to do sum in the end . Is there any way by which i can sum employee work time. (i tried rollover, its not fulfilling my requirements, can any expert guide me how to do with loops so that i can get following output as show in below pic
When I was new to SQL, I always looped. Then I realized that let the database do the job was normally smarter. Without table structure and desired output it is hard to say. Do a db fiddle so it is easier to understand.
Get the all the data in the desired format from the database and then create and add to table.
What is the wrktime column definition and what are some of the actual values in it? Is the 8:00 example actually stored as 8:00 or is it 8:00:00?
Next, the picture you posted makes no sense. What is the actual result you are trying to produce? Are you trying to list all the rows for every employee (for some range of dates or for some job id?), with a total row between each employee? Or are you trying to list one row for each employee and a grand total at the end?
The SUM(wrktome) wasn’t the total number of seconds. It was treating the values as integers, e.g. 800 + 730 + 730 = 2260 and is meaningless because times are a mixed base number and cannot simply be added.
Regardless, of what result you are trying to produce, these values are quantities of hours:minutes (through I suspect you are actually storing them in the database as minutes:seconds), not time of day values. The math would involve splitting the values at the : character and calculating the number of minutes = hours x 60 + minutes, adding the number of minutes together, then converting the total number of minutes back to hours:minutes at the end for display purposes.