[英]get total working hours from mysql with pdo
I want to get my total working hours. 我想得到我的总工作时间。
Saved as started time and end time 保存为开始时间和结束时间
$sql = "SELECT end_service, start_service FROM stage ORDER BY stage_id ASC";
$sql = $db->query($sql);
foreach($sql as $row) {
$count = round((strtotime($row['end_service']) - strtotime($row['start_service'])) / 3600);
}
echo $count;
Providing your not recieiving any database errors, you need to set a count outside your foreach loop which is added to in each iteration. 如果您没有收到任何数据库错误,则需要在foreach循环外设置一个计数,该计数将在每次迭代中添加。
$sql = $db->query($sql);
$count = 0;
foreach($sql as $row) {
$count += round((strtotime($row['end_service']) - strtotime($row['start_service'])) / 3600);
}
echo $count;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.