在 php 中显示月度报告

Display month wise report in php

我正在开发一个基于 Web 的应用程序,用于跟踪员工的日常活动。我在 php 中制作了表格,他们在其中输入了详细信息。还有一个选项,他们可以在其中显示报告。

这是我到目前为止所做的。

<?php

$serverName = "";
$connectionInfo = array("Database" => "...", "UID" =>"...", "PWD"=>"..." );
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false){
    die(print_r(sqlsrv_errors(),true));
}

$$sql = "(Select Ad.[Act] 'Act', Ad.[Units] 'Units', Ad_Acts.[Name] from Ad JOIN Ad_Act ON Ad.ActID = Ad_Act.ActAttend)
        Union ALL(Select Citi.[Act2] 'Act', Citi.[Units2] 'Units', Citi_act.[Name] from Citi JOIN Citi_Acts ON Citi.ActID2 = Citi_Act.ActAttend2)
         Union ALL(Select ComOut.[Act3] 'Act', ComOut.[Units3] 'Units', ComOut_Act.[Name] from ComOut JOIN ComOut_Act ON ComOut.ActID3 = ComOut_Act.ActAttend3)
         Union ALL(Select ReSchAct.[Act4] 'Act', ReSchAct.[Units4] 'Units', ReSch_Act.[Name] from ReSchAct JOIN ReSch_Act ON ReSchAct.ActID4 = ReSch_Act.ActAttend4)
          Union ALL(Select TeEd.[Act5] 'Act', TeEd.[Units5] 'Units', TeEd_Act.[Name] from TeEd JOIN TeEd_Act ON TeEd.ActID5 = TeEd_Act.ActAttend5)";


$totalUnits = 0;
?>

<table>
    <tr>
        <th>Act</th>
        <th>Units</th>
        <th>Name</th>
    </tr>
<?php while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) : ?>
    <tr>
        <td><?php echo $row['Act']</td>
        <td><?php echo $row['Units']</td>
        <td><?php echo $row['Name']</td>
    </tr>
    <?php $totalUnits = $totalUnits + intval($row['Units']); ?>
<?php endwhile; ?>
    <tr>
        <td></td>
        <td>Total Units: </td>
        <td><?php echo $totalUnits; ?></td>
    </tr>
</table>

现在我想做一些让用户可以显示月度报告的东西。用户应该可以选择月份并查看报告。

以上代码从数据库的不同表中获取数据。显示单位总和(即用户到目前为止获得的总分)。上面的代码现在可以正常工作了,我必须按月显示它。

您需要做的就是在您的 table 中有一个月份列,然后 select 特定于用户正在解析的月份的记录..

尝试将日期列拆分为日、月和年。然后查询月份列。那应该可以解决问题。