PHP和变量在while循环 我要“和”变量中,而值,这里我们我的例子:PHP和时间变量while循环
while($row = mysql_fetch_array($result)){
$working_hour= $row[working_hour];
}
上面会输出的代码,如果我把echo $working_hour;
例如: 01:00:03,01:03:04,01:10:15 我想要像sum($ working_hour)或array_sum($ working_hour)来计算while循环的所有结果。所以,我要算:1时00分03秒,1时03分04秒,01:10:15 = 3点13分22秒 我试着这样说:
$total_working_hour=’00:00:00’;
while($row = mysql_fetch_array($result)){
$working_hour= $row[working_hour];
$total_working_hour+= $working_hour;
}
Echo $total_working_hour;
上面的代码提供输出:
03
我该怎么用php做到这一点? 感谢
你可以与我们分享这个查询吗? –
我只想提***作为一个非常重要的方面说明,你不应该使用mysql_ *函数,而应该使用PDO或MySQLi。***旧的mysql扩展已被弃用多年,并从PHP 7中删除。请参阅手册中的[选择API](http://php.net/manual/en/mysqlinfo.api.choosing.php)以获取更多关于如何更新代码的信息。 – Sherif