Quality ranking of imported milk powder the PHP record accumulates and displays the total time of the second result

Source: Internet
Author: User
Tags explode
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.