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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.