Php 将时间值相加形成一个总时间

Php 将时间值相加形成一个总时间,php,mysql,Php,Mysql,我有下面的代码,我希望总数是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 he

我有下面的代码,我希望总数是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>";
$sql=“SELECT hesk_categories.name,COALESCE(NULLIF(SEC_TO_TIME)(SUM(TIME_TO_SEC(timespunt))),0),'00:00:00')作为hesk_categories左连接hesk_categories上的hesk_票证。id=hesk_票证左连接hesk_票证上的timespunt.id和(日期创建于日期_格式(NOW(),'%Y-%m-01')和NOW())其中hesk_categories.name“功能请求”组由hesk_categories.name组成;
$query=mysqli\u query($con,$sql);
while($row=mysqli\u fetch\u数组($query))
{
$timespunt=$row['timespunt'];
$TimeSpent=$TimeSpent+$TimeSpent;
$message.=“”;
$message.=''.$row['name'].'';
$message.=''.$row['timespunt'].'';
$message.=“”;
}
$message.=“”;
$message.=“总计”;
如果($TimeSpent>='10:00:00')
{
$message.=“..$timespunt.”(该月的支持小时数已超过10小时。)”;
}
其他的
{
$message.=''.$timespunt.'';
}
$message.=“”;
$message.=“
”;
我在查询中添加了以下内容:

SUM(TIME_TO_SEC(TimeSpent)) as TimeSpentSeconds
这是if声明的一部分:

if ($TimeSpentSeconds >= 36000)
{
    $TimeSpentSeconds = $TimeSpentSeconds / 3600;
    $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
{
    $TimeSpentSeconds = $TimeSpentSeconds / 3600;
    $message.="<td>" . $number_format((float)$TimeSpentSeconds, 2, '.', '') . " hrs</td>";
}
如果($TimeSpentSeconds>=36000)
{
$TimeSpentSeconds=$TimeSpentSeconds/3600;
$message.=''.number_格式((float)$TimeSpentSeconds,2','.'','')“小时(当月的支持小时数已超过10小时)。”;
}
其他的
{
$TimeSpentSeconds=$TimeSpentSeconds/3600;
$message.=''.$number_格式((浮点)$TimeSpentSeconds,2','.'',''),''。“hrs”;
}

他做这项工作

为什么要执行
$timespunt=$row['timespunt']$TimeSpent=$TimeSpent+$TimeSpent?您想添加时间还是添加小时、分钟、秒的总数?是的,总时间包括小时、分钟、秒您最好从数据库中获取以秒为单位的时间,然后用PHP格式化显示(或同时获取两者)。您的代码试图将两个格式化的时间相加为数字(并且也不会累加总数)。您不能简单地计算小时、分钟。如果($timespunt>='10:00:00'),则执行
if($timespunt>='10:00:00')
有点糟糕。我认为这可能会奏效,但你不是在比较日期,而是在比较字符串,你永远不知道结果会怎样。