我需要阅读一张代表每月登记的表格。有点像
year, month, name, d1...d31 <--days of the month
我使用这个函数来获取当月的全球小时数
function calchour($db, $table, $year, $month)
{
$daysinmonth =cal_days_in_month(CAL_GREGORIAN, $month, $year);//Nbr of days in month
$tt_hour = '0';
$result = mysqli_query($db,"SELECT * FROM $table WHERE anno = '$year' AND month = '$month'") or merror($msg = mysqli_error($db));
while ($row = mysqli_fetch_array($result))
{
$volhr = '0';
for ($i = '1'; $i <= $daysinmonth; $i++) {
$day = 'd'.$i;
$hour = $row[$day];
if (($hour != '')) { $volhr = $volhr + $hour; }
}
$tt_hour = $tt_hour + $volhr;
}
return $tt_hour;
}
有没有更好的方法来获取当月的全球小时数?
繁星coding