duanlang1196 2018-09-15 13:07
浏览 64
已采纳

从时间跟踪器到日历的总时数

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.

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?

This is my current code:

<?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 

?

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) enter image description here

The desired output would be to have 146 on the day it's summarized from listed in the calendar, and the same for each and every other day but with those days hours.

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

Sample 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
  • 写回答

1条回答 默认 最新

  • duanjue7508 2018-09-16 13:26
    关注

    Figured it out!

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度