naveendk.55 Posted November 28, 2011 Share Posted November 28, 2011 I have a column with time in HH:MM:SS format. How to add the total time in this column? I tried the below steps but o/p display only 1.. $qry = "select SEC_TO_TIME(SUM(TIME_TO_SEC(time_utilization))) from tracker"; $result=mysql_query($qry) or die (mysql_error()); $row = mysql_num_rows($result); echo $row; Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/ Share on other sites More sharing options...
joel24 Posted November 28, 2011 Share Posted November 28, 2011 try this from http://forums.mysql.com/read.php?20,194872,194872 SELECT SEC_TO_TIME(SUM(SECOND(time_utilization))) FROM tracker; Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1291779 Share on other sites More sharing options...
naveendk.55 Posted November 28, 2011 Author Share Posted November 28, 2011 tried that and getting the error :Notice: Undefined index: time_utilization in C:\wamp\www\strategyone\testing.php on line 28" Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1291827 Share on other sites More sharing options...
ignace Posted November 28, 2011 Share Posted November 28, 2011 That's a PHP error not MySQL. Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1291851 Share on other sites More sharing options...
naveendk.55 Posted November 28, 2011 Author Share Posted November 28, 2011 Below is the my code. If the error is resolved, then I'll put the code in the program to get full result. If it display the total, then I'll be able to resolve it. Below is the full code in my page except database connection include file. $qry = "SELECT SEC_TO_TIME(SUM(SECOND(time_utilization))) FROM tracker"; $result=mysql_query($qry) or die (mysql_error()); $row = mysql_fetch_array($result); echo $row; Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1291891 Share on other sites More sharing options...
fenway Posted November 28, 2011 Share Posted November 28, 2011 Of course it only displays "1" -- that's boolean truth. You need to get the value for that expression -- with mysql_result() or by giving it an alias and using fetch_assoc(). Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1291912 Share on other sites More sharing options...
The Little Guy Posted November 29, 2011 Share Posted November 29, 2011 This works for me (result is in seconds): select sum((hour(the_time) * 60 * 60) + (minute(the_time) * 60) + (second(the_time))) as seconds from test; Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1292395 Share on other sites More sharing options...
The Little Guy Posted November 29, 2011 Share Posted November 29, 2011 I widthdraw my previous post with a quicker way: select sec_to_time(sum(time_to_sec(the_time))) as total_time from test; this will return something like: 120:20:13 if you want seconds, remove the sec_to_time function. Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1292405 Share on other sites More sharing options...
naveendk.55 Posted November 30, 2011 Author Share Posted November 30, 2011 Thanks Little Guy. That helped me and thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/251937-adding-total-time-in-a-column/#findComment-1292490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.