2014-01-05 100 views
-2

用這個掙扎!計算小時和分鐘數組的總和php

我需要在PHP中所有不同點的總和所以這裏的源

$du = mysql_query("select SUBTIME(timeto,timefrom) as diff from table"); 

while($d = mysql_fetch_assoc($du)) 
{ 

    $total[] = strtotime($d["diff"]); 

} 

$t = array_sum($total); 

echo gmdate("H:i", $t); 

之前你說...我知道我應該使用PDO或mysqli的

不幸的是我需要的解決方案在PHP

+0

如何使用MySQL的TIMEDIFF() – Jompper

回答

1
$du = mysql_query("SELECT SUM(TIME_TO_SEC(TIMEDIFF(timeto, timefrom))) AS TOTAL_SEC FROM table"); 

$d = mysql_fetch_assoc($du); 

echo gmdate("H:i", $d["TOTAL_SEC"]); 
+0

謝謝 - 我需要在PHP中我將編輯OP – user3105417

+0

那個快啊!非常感謝 – user3105417

+0

不客氣...請記住要評分答案... –

相關問題