Now there is a MySQL database in the test table has a Duration field, which has three records:
00:22:32
13:42:21
134:42:21
Represents the time length, however, the save type is text.
Now, how do you add these records in PHP and end up as a result of a total length of seconds?
Copy Code code as follows:
Connect database ... Slightly
$total = 0; Total number of seconds
$sql = "Select duration from Test";
$rs = mysql_query ($sql);
while ($row = Mysql_fetch_array ($rs))
{
$arr =explode (":", $row [duration]);
$h = $arr [0]*60*60;
$m = $arr [1]*60;
$s = $arr [2];
$total = $h + $m + $s;
}
Echo $total;
This is mainly to query the data, and then use the Explode function to ":" Split the string, get an array.
Then calculate the hours corresponding to the number of seconds, minutes corresponding to the number of seconds. And then add up the number of seconds.
Finally, the total number of seconds is obtained.