0
我有一个包含日期的2列的mySQL表。 while循环将每个变量放入一个变量中:$ start_date和$ end_date,计算它们之间的时间,并通过使用diff()将它们放入一个新变量$ since_start中;据我了解在DateInterval类中使用diff()结果。在循环内递增DateInterval
现在我想在'while'循环中创建一个总和并将其存储在$ total_received变量中。最后一件事,我试图搜索网络和计算器后,是
$total_received->add(new DateInterval($since_start));
但这似乎是错误的,因为我没有得到任何输出。我不明白我在做什么错,但我不完全知道我在这条线上做什么,说实话,不知道要看什么。我希望我能通过谷歌找到答案,因为这更快,但我不能。我希望你能帮助!
下面是完整的循环,其中前面定义了$ total_received变量,然后放出。
//Set variable for lifetime received total
$total_received = 0;
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo
$row["id"] ." "
. $row["donor"]." ";
$start_date = new DateTime($row["start"]);
$end_date = new DateTime($row["end"]);
$since_start = $start_date->diff($end_date);
$total_received->add(new DateInterval($since_start));
echo $since_start->format('%h')." Hours ".$since_start->format('%i')." Minutes "
. $row["subject"] ." "
. $row["complete"] ."<br>";
}
} else {
echo "No lifetime received yet";
}
echo $total_received->format('%h')." Hours ".$total_received->format('%i')." Minutes ";
非常感谢您提前!