Search code examples
phphtmlsql-servernetbeansreport

Display month wise report in php


I'm working on a web based application which tracks the daily activities of employees. I've made forms in php in which they enter their details. Also there is an option in which they can diplay the report.

Here is what I've done so far.

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

Now I want to make something such that the user could display the month wise report. The user should have option of selecting the month and view the report.

The above code takes data from different tables of the database. Displays the sum of Units(i.e the total score the user has earned so far). The above code is working now i've to display it month wise.


Solution

  • Try splitting the date column to day, month and year. Then query the month column. That should solve the problem.