There is a duration field in the test table of the mysql database, which contains three records:
00:22:32
13:42:21
134: 42: 21
It indicates the duration. However, the storage type is text.
Now, we need to use php to accumulate these records and display the results in seconds?Copy codeThe Code is as follows: // connect to the database...
$ Total = 0; // The 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 we mainly query the data and use the explode function to split the string with ":" To get an array.
Then calculate the number of seconds corresponding to the hour, and the number of seconds corresponding to the minute. Then sum up the seconds.
The total number of seconds is obtained.