gpt4 book ai didi

php - 每天从时间跟踪器到日历的总小时数

转载 作者:行者123 更新时间:2023-11-29 17:00:03 25 4
gpt4 key购买 nike

我有一个工作日历函数,以及一个用于从时间跟踪器计算项目时间的工作总和,但我很难将它们合并到一个工作函数中。

查看代码中的注释以了解当前进度,下面还提供了打印屏幕。

如何让 QUERY 根据日历中每行的 $year $month 和 $day_num 回显 SUM?

这是我当前的代码:

<?php 

include 'db.php';

// GET USER DATA

$sql = "SELECT * FROM users where user_username = '".$_SESSION['username']."'";
$result = $mysqli->query($sql);

while($row = $result->fetch_assoc()) {
$loginuser_id = $_GET['id'];
}

// GET TIME TRACKING DATA

$query = "
SELECT userhours_id, user_hours, hours_timeoccur, SUM(user_hours) as 'myhours' FROM hours h
where h.userhours_id = $loginuser_id
AND h.hours_timeoccur = '2018-09-15'
";

$result = $mysqli->query( $query ) or die($mysqli->error);

$row = $result->fetch_assoc();

$user_hours = $row['myhours'];

// VIEW THE SUM OF HOURS BASED ON THE DAY FROM THE QUERY ABOVE

echo $user_hours;

// THE CALENDAR

showmonth($m = $_GET['m'] ,$y = $_GET['y']);

function showmonth($month, $year) {

$first_day = mktime(0,0,0,$month, 1, $year);
$title = date('F', $first_day);
$day_of_week = date('D', $first_day);
$days_in_month = cal_days_in_month(0, $month, $year);

echo "<div id='container'>";
echo "<div id='datenav'>";
echo "<div id='prevbtn'>prev</div>";
echo "<div id='date'>$title $year</div>";
echo "<div id='nextbtn'>next</div>";
echo "</div>";
echo "<div id='cal'>";
$day_num = 1;
while ( $day_num <= $days_in_month ) {
$cnt = 0;
while ($cnt < 7) {
echo "<div id='days'>";
echo "<h4>$day_num</h4>";
echo "<h5>40h</h5>"; // HERE I WANT THE SUM OF TIME TRACKING BY EACH DAY
echo "</div>";
$day_num++;
if ($day_num > $days_in_month) {break;}
}
}
echo "</div>";
echo "</div>";

} // end of function

?

当前输出:(146是QUERY中指定日期的所有小时的总和,图中所有40小时都是手动写入的。这就是我要回显每天的QUERY输出的地方) enter image description here

期望的输出是从日历中列出的汇总当天得到 146,并且每隔一天都相同,但这些天的时间相同。

提前非常感谢,如果您需要更多数据,请告诉我!

示例数据:

DB: hours
hours_id userhours_id projecthours_id user_hours hours_timeoccur
1 5 12377 5 2018-08-14
2 3 12378 100 2018-09-15
3 3 12378 46 2018-09-15
4 1 12378 5 2018-09-16
5 5 12379 5 2018-09-17

DB: users
user_id user_username .....
1 Adam
2 Bryan
3 Clinton
4 David
5 Eric

DB: projects
project_id project_name .....
1 My first test
2 My second test
3 My third test
4 My fourth test
5 My fifth test

最佳答案

明白了!

我将查询移到了日历代码中,然后一切都很完美!

关于php - 每天从时间跟踪器到日历的总小时数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com