Home >Backend Development >PHP Tutorial >Imported milk powder quality ranking PHP records are accumulated and the results are displayed with a total duration of seconds
Now there is a duration field in the test table of a mysql database, which contains three records:
00:22:32
13:42:21
134:42:21
indicates the duration, but the save type is text.
Now I am asking, how can I use php to accumulate these records and finally display the result as a total duration of seconds?
Copy the code The code is as follows:
//Connect to the database... slightly
$total = 0; //Total 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;
The above introduces the imported milk powder quality ranking PHP records to accumulate and display the results with a total duration of seconds, including the content of the imported milk powder quality ranking. I hope it will be helpful to friends who are interested in PHP tutorials.