每天从时间跟踪器到日历的总小时数 [英] Sum hours from time tracker to calendar by day

查看:91
本文介绍了每天从时间跟踪器到日历的总小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作日历功能,还有一个工作总和,用于从时间跟踪器计算项目工时,但是我正在努力将它们组合成一个工作功能.

I've got a working calendar function, and a working sum to calculate the project hours from the time tracker, but I'm struggeling to combine them into a working function.

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

See comments in code to figure out the current progress, a printscreen is also provided below.

如何获取查询以基于日历中每一行的$ year $ month和$ day_num回显SUM?

How can I get the QUERY to echo out the SUM based on the $year $month and $day_num on each row in the calendar?

这是我当前的代码:

<?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中指定日期的所有小时的总和,并且图片中的所有40h都是手动写入的.这是我每天要回显QUERY输出的地方)

The current output: (146 is the SUM of all the hours on the specified date in the QUERY, and all the 40h in the picture are manually written. That's the place that I want to echo the QUERY output for each day)

期望的输出将是从日历中列出的那一天开始的146,并且每隔一天都是相同的,但带有这些天的小时数.

在此先感谢您,如果您需要更多数据,请告诉我!

Big thanks in advance and let me know if you need any more data!

样本数据:

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

推荐答案

想通了!

我在日历代码中移动了QUERY,然后一切都完美了!

I moved the QUERY inside the calendar code and then it all worked out just perfect!

这篇关于每天从时间跟踪器到日历的总小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆