0

I'm trying to get the total time duration of all time variables from the database. But I don't seem to get the right total or result. This is my code...

    $len = count($mids);
    foreach($mids as $key => $val)
    {
        $result=mysql_query("SELECT * FROM tbltempmovies WHERE mid='".$val."'");
        while($row=mysql_fetch_array($result))
        {
            $dur += strtotime($row['duration']);
        }
    }
    $duration = date('g:i:s', $dur);

PS: I know I'm not using mysqli or PDO. I'll fix that once I'm done with this.

Brentoy
  • 1
  • 4
  • the expected result is more than 12 hours ? – Frankich Aug 08 '17 at 12:21
  • This may be help you!!! https://stackoverflow.com/questions/33837435/php-addition-of-multiple-durations-to-get-total-duration – GuRu Aug 08 '17 at 12:22
  • Possible duplicate of [Calculating total hours out of database](https://stackoverflow.com/questions/34158810/calculating-total-hours-out-of-database) – GuRu Aug 08 '17 at 12:25
  • GuRu it worked. thanks a lot :) – Brentoy Aug 08 '17 at 14:38
  • Note that [`TIME` data type](https://dev.mysql.com/doc/refman/5.7/en/time.html) has a limit in MySQL, which is `838:59:59`. So make sure you don't exceed it with `SELECT SUM(duratation) FROM ...` – Paul Spiegel Aug 08 '17 at 22:28

1 Answers1

0

try this

$duration = date('g:i:s', strtotime($dur));
chigs
  • 178
  • 2
  • 12