猿问

将时间值加在一起形成总计

我有下面的代码,我希望总数是 12:37:47,但我得到的是 12 的整数。这些是结果:


类别 1 - 06:02:06


类别 2 - 06:35:41


总计 - 12


我怎样才能得到 12:37:47 的总结果?


$sql    = "SELECT hesk_categories.name, COALESCE(NULLIF(SEC_TO_TIME(SUM(TIME_TO_SEC(TimeSpent))),0),'00:00:00') AS TimeSpent from hesk_categories left Join hesk_tickets on hesk_categories.id = hesk_tickets.category left join TimeSpent on hesk_tickets.id = TimeSpent.ID and (DateCreated between  DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() ) where hesk_categories.name <> 'Feature Request' group by hesk_categories.name";

$query  = mysqli_query($con, $sql);

while ($row = mysqli_fetch_array($query))

{

    $TimeSpent = $row['TimeSpent'];

    $TimeSpent = $TimeSpent + $TimeSpent;


    $message.="<tr>";

    $message.="<td>" . $row['name'] . "</td>";

    $message.="<td>" . $row['TimeSpent'] . "</td>";

    $message.="<tr>";

}


$message.="<tr>";

$message.="<td>Total</td>";



    if ($TimeSpent >= '10:00:00')

    {

        $message.="<td><b><font color='red'>" . $TimeSpent . " (Support Hours have exceeded 10 hours for the month.)</font></b></td>";

    }

    else

    {

        $message.="<td>" . $TimeSpent . "</td>";

    }

$message.="</tr>";

$message.="</table><br>";


呼如林
浏览 124回答 1
1回答

慕仙森

我将此添加到查询中:SUM(TIME_TO_SEC(TimeSpent)) as TimeSpentSeconds这对于 if 语句:if ($TimeSpentSeconds >= 36000){&nbsp; &nbsp; $TimeSpentSeconds = $TimeSpentSeconds / 3600;&nbsp; &nbsp; $message.="<td><b><font color='red'>" . number_format((float)$TimeSpentSeconds, 2, '.', '') . " hrs (Support Hours have exceeded 10 hours for the month.)</font></b></td>";}else{&nbsp; &nbsp; $TimeSpentSeconds = $TimeSpentSeconds / 3600;&nbsp; &nbsp; $message.="<td>" . $number_format((float)$TimeSpentSeconds, 2, '.', '') . " hrs</td>";}做这份工作。
随时随地看视频慕课网APP
我要回答