Jump to content

problem with sum()


dreamwest

Recommended Posts

Ive tried everything to get this to work, but it keeps displaying the same result over and over even though the column has new times added

 

I have a column with time format :

 

12:50

4:30

1:20

 

etc...

 

$query = "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(length))) FROM table"; 
$result5 = mysql_query($query) or die(mysql_error());

$row5 = mysql_fetch_array($result5);

$total_hours = $row5['SEC_TO_TIME(SUM(TIME_TO_SEC(length)))'] * 60 ;

echo $total_hours;

Link to comment
https://forums.phpfreaks.com/topic/157952-problem-with-sum/
Share on other sites

Your total hours calculation does not make sense for a couple of reasons. You are multiplying a number that has two different number bases minutes:seconds by 60 and to get hours you would generally need to divide the minutes by 60 to get the whole number of hours.

Link to comment
https://forums.phpfreaks.com/topic/157952-problem-with-sum/#findComment-833220
Share on other sites

Your total hours calculation does not make sense for a couple of reasons. You are multiplying a number that has two different number bases minutes:seconds by 60 and to get hours you would generally need to divide the minutes by 60 to get the whole number of hours.

 

Ok this will get total minuets - before the deliminator ":"

 

$query = "SELECT SUM((length) FROM table";
$result5 = mysql_query($query) or die(mysql_error());

$row5 = mysql_fetch_array($result5);

$total_minuets = $row5['SUM(TIME_TO_SEC(length)'] ;

echo $total_hours;

 

But how can i get the sum of seconds after the ":"

Link to comment
https://forums.phpfreaks.com/topic/157952-problem-with-sum/#findComment-833595
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.