使总数等于分钟和秒数

时间:2016-01-15 16:24:45

标签: php sql mysqli

以下代码从数据库中获取人们的“时间”。我希望它总计为分钟和秒,就像它只显示一个数字一样。

<?php
    //MySqli Select Query
    $results = $mysqli->query("SELECT *, (r1 + r2 + r3 + r4 + r5) AS total FROM test WHERE event = '1' ORDER BY total DESC");
    $title = $mysqli->query("SELECT * FROM test");

    $all_cols=array("rt1" => "r1","rt2"=> "r2","rt3"=> "r3","rt4"=> "r4","rt5"=> "r5");

    while ($t = $title->fetch_assoc()){
        // remember empty cols
        $empty_cols=array();

        echo "<table width=\"1000\" cellpadding=\"5\" cellspacing=\2\" class=\"entrywriting\" align=\"center\">
        <tr align=\"center\">
        <td>Overall</td>
        <td>Competitor</td>";

        foreach ($all_cols as $col => $value) {
            if (!empty($t[$col])) {
                echo "<td>" . $t[$col] . "</td>";
            } else {
                // set this column as empty for later
                $empty_cols[]=$col;
            }
        } unset($col); unset($value);
        echo "
        <td>Total</td>
        </tr>";
    }

    //set counter
    $counter = 1;
    while($row = $results->fetch_assoc()) {
        echo "<tr align=\"center\">";
        echo "<td>" . $counter . "</td>";
        echo '<td>'.$row["driver"].'</td>';

        foreach ($all_cols as $col => $value) {
            if (!in_array($col, $empty_cols)) {
                // echo non-empty values
                echo '<td>'.$row[$value].'</td>';
            }
        } unset($col); unset($value);
        echo '<td>'.$row["total"].'</td>';

        $counter++; //increment count by 1
    }  
    echo "</table>";

    ?>

如何才能达到分钟和秒数? R1 - R5是一圈的实际时间,所以我们说

lap 1 = 00:01:01
lap 2 = 00:00:59
lap 3 = 00:00:45
this would be a total of: 00:02:45 HH:MM:SS

rt1 - rt5是球场或圈数。

所以我想要r1 + r2 + r3 + r4 + r5到total = HH:MM:SS将数据库设置为时间。

1 个答案:

答案 0 :(得分:0)

您可以使用:

DATE_ADD(TOTAL,Rx)在循环中,x = 1到5