Now there is a MySQL database with a Duration field in the test table with three records:
00:22:32
13:42:21
134:42:21
Represents the length of time, however, the save type is text.
Now, how do you accumulate these records in PHP, and then show them as a result of a total time of seconds?
Copy the Code code as follows:
Connect to 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;
Here the main is to query out the data, and then use the Explode function, ":" To split the string, get an array.
Then calculate the number of seconds corresponding to the hour, and the number of seconds corresponding to the minutes. And then add up the number of seconds.
Finally get the total number of seconds.
The above on the introduction of the quality of imported milk powder list PHP records to accumulate and show the total time of the results of the second, including the quality of imported milk powder List of content, I hope that the PHP tutorial interested friends have helped.