简体   繁体   English

使用 PHP MYSQL 生成每月日期和小时明智的报告

[英]Monthly Date and Hour wise report generation using PHP MYSQL

Attendance Portal in PHP PHP 考勤门户

I am facing problem at Final Attendance Report Generation我在生成最终出勤报告时遇到问题

I'm stuck at the final stage of the Project:我被困在项目的最后阶段:

I have a Table- attendance, If a student is Present I mark it as 1 if absent 0. we have date,dayorder,hour (we are following Day Order Time Table)我有一个表 - 出勤,如果学生在场,我将其标记为 1,如果缺席 0。我们有日期,日订单,小时(我们遵循日订单时间表)

Table 
dayorder:
    id day
    1 day1
    2 day2
    3 day3
    4 day4
    5 day5
    6 SAT
    7 day6

Table 
Hour:
   id
    1
    2
    3
    4
    5
    6
    7

Table attendance:表出席: 在此处输入图片说明

I must generate a Monthly report like a register as below我必须生成一个像下面这样的寄存器的月度报告

在此处输入图片说明 在此处输入图片说明

Code I have Tried:我试过的代码:

SELECT student_id,deptno,Month, Year_c,
branch.description as bdesc,
course.coursecode as ccd, 
users.firstname as ufn, 
users.lastname as uln,
course.description as ccdes,schedules.hour as hhour,
h,dayorder,AttdDate,
CONCAT(AttdDate,h,dayorder) AS fate,
IF(Day_c=1, p, " ") AS '1',
IF(Day_c=2, p, " ") AS '2',
IF(Day_c=3, p, " ") AS '3',
IF(Day_c=4, p, " ") AS '4',
IF(Day_c=5, p, " ") AS '5',
IF(Day_c=6, p, " ") AS '6',
IF(Day_c=7, p, " ") AS '7',
IF(Day_c=8, p, " ") AS '8',
IF(Day_c=9, p, " ") AS '9',
IF(Day_c=10, p, " ") AS '10',
IF(Day_c=11, p, " ") AS '11',
IF(Day_c=12, p, " ") AS '12',
IF(Day_c=13, p, " ") AS '13',
IF(Day_c=14, p, " ") AS '14',
IF(Day_c=15, p, " ") AS '15',
IF(Day_c=16, p, " ") AS '16',
IF(Day_c=17, p, " ") AS '17',
IF(Day_c=18, p, " ") AS '18',
IF(Day_c=19, p, " ") AS '19',
IF(Day_c=20, p, " ") AS '20',
IF(Day_c=21, p, " ") AS '21',
IF(Day_c=22, p, " ") AS '22',
IF(Day_c=23, p, " ") AS '23',
IF(Day_c=24, p, " ") AS '24',
IF(Day_c=25, p, " ") AS '25',
IF(Day_c=26, p, " ") AS '26',
IF(Day_c=27, p, " ") AS '27',
IF(Day_c=28, p, " ") AS '28',
IF(Day_c=29, p, " ") AS '29',
IF(Day_c=30, p, " ") AS '30',
IF(Day_c=31, p, " ") AS '31'
FROM
(SELECT *,DAY(date) AS Day_c, 
MONTHNAME(date) AS Month, 
Year(date) AS Year_c,
date(date) AS AttdDate,hour as h, day as dayorder,
(CASE  WHEN present = 1 
    THEN 'P'
    WHEN present = 0 
    THEN 'A'
    WHEN present is null   
    THEN ' '
END) AS p
FROM attendance a 
WHERE date between '$from' AND '$to' And branch = $branchid AND coursecode = $courseid AND batch = $batchid
GROUP BY student_id
ORDER BY student_rollno ASC 
)
as report 
LEFT JOIN branch on branch.id = report.branch
LEFT JOIN course on course.id = report.coursecode
LEFT JOIN users on users.id = report.user
LEFT JOIN schedules on schedules.id = report.hour
ORDER BY Month DESC, Year_c DESC

OUTPUT in PHPMYADMIN PHPMYADMIN 中的输出在此处输入图片说明 But I am not able to show up as a HTML Page using PHP and MY SQL但是我无法使用 PHP 和 MY SQL 显示为 HTML 页面

I write an example for PHP MySQL your case but didn't get your SQL exactly why you have day in description also on the first head no idea.我为 PHP MySQL 写了一个例子,你的情况,但没有得到你的 SQL 到底为什么你在第一个头也不知道为什么你有一天的描述。 Also, you have to add your code for hours that's just a correct way to PHP MySQL example also I suggest you to use ez_SQL better object programming with oho MySQL if you stuck don't hesitate to comment此外,您必须将代码添加数小时,这只是 PHP MySQL 示例的正确方法,我建议您使用 ez_SQL 更好的对象编程与 oho MySQL,如果您卡住了,请不要犹豫,发表评论

    <?php
    $sql="SELECT * FROM attendance ORDER BY student_id ASC, date ASC";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        // output data of each row
        echo "<table><thead><tr><td># Student ID</td><td>Dept No</td><td>Description</td>";
        for ($i=0; $i < $day; $i++) { 
            echo "<td>".$i."</td>";
        }
        echo "</tr></thead><body><tr>";

        while($row = $result->fetch_assoc()) {
            $student_id = $row->student_id;
            $deptno = $row->deptno;
            $decp = $row->date." ".$row->semester." ".$row->day;
            $absence = $row->present;
            if(isset($temp) and $temp != $student_id){
                echo "</tr>";
                echo "<tr>";
                echo "<td>".$student_id."</td><td>".$deptno."</td><td>".$decp."</td>"
            }elseif(!isset($temp)){
                echo "<td>".$student_id."</td><td>".$deptno."</td><td>".$decp."</td>";
            }

            echo "<td>".$absence."</td>";
            $temp = $student_id;

        }
echo "</tr></tbody></table>";
    } else {
        echo "0 attendance taken";
    }

I did it in PHP我是用 PHP 做的

<?php 
include 'includes/session.php';

if(isset($_POST["from"], $_POST["to"],$_POST["branchid"],$_POST["courseid"],$_POST["batchid"])){
        $from = $_POST["from"];
        $to = $_POST["to"];
        $branchid = $_POST["branchid"];
        $courseid = $_POST["courseid"];
        $batchid = $_POST["batchid"];
        $presentd = array();
        $datea = array();
        $daya = array();
        $houra = array();
        $TotStudents = array();
        $th="";
        $td="";
        $perpre = "";
        $A = array();
        $Studenttblbodypresent = "<table id='Studentpresent' class='table table-bordered dataTable no-footer '>
        <thead class = 'thead-present'><tr><th>DeptNo</th>";

        $Studenttblbody = "";
        $stdsql =   "SELECT deptno,name
                    FROM attendance a WHERE
                    date between '$from' AND '$to' AND a.branch = $branchid AND a.coursecode = $courseid AND a.batch = $batchid
                    GROUP BY student_id
                    ORDER BY student_rollno ASC";
        $querystd = $conn->query($stdsql)or die($conn->error);
        $studentNo = $querystd->num_rows;
        if($studentNo >0){
        // report common header
        $sql =  "SELECT MONTHNAME(date) AS Month,
                        branch.description as bdesc,
                        course.coursecode as ccd, 
                        users.firstname as ufn, 
                        users.lastname as uln,
                        course.description as ccdes,
                        schedules.hour as hhour,
                        day.description as dday,
                        a.hour as hourid,
                        day,course.semester as sem,date(date) AS AttdDate
                 FROM attendance a
                    LEFT JOIN branch on branch.id = a.branch
                    LEFT JOIN course on course.id = a.coursecode
                    LEFT JOIN users on users.id = a.user
                    LEFT JOIN schedules on schedules.id = a.hour
                    LEFT JOIN day on day.id = a.day
                 WHERE date between '$from' AND '$to' AND a.branch = $branchid AND a.coursecode = $courseid AND a.batch = $batchid
                 GROUP BY AttdDate";

            $query = $conn->query($sql)or die($conn->error);                
            $dateNo = $query->num_rows;
            $rowd = $query->fetch_assoc();
            if($rowd['sem'] == 6){$sem = 'VI';}
            else if($rowd['sem'] == 5){$sem = 'V';}
            else if($rowd['sem'] == 4){$sem = 'IV';}
            else if($rowd['sem'] == 3){$sem = 'III';}
            else if($rowd['sem'] == 2){$sem = 'II';}
            else if($rowd['sem'] == 1){$sem = 'I';}
            else {$sem = "";}
            //report header
            $RepHdrtblbody =    "<tr role='row'>
                                <td>".$rowd['Month']."</td>
                                <td>".$sem."</td> 
                                <td>".$rowd['bdesc']."</td>
                                <td>".$rowd['ccdes']."</td> 
                                <td>".$rowd['ccd']."</td>
                                <td>".$rowd['ufn']." ".$rowd['uln']."</td>
                                <td>".$dateNo."</td>
                                </tr>";
                $th ='<td class="dispdates"><span>'.$rowd['AttdDate'].'<br>'.$rowd['hhour'].'<br>'.$rowd['dday'].'</span></td>';
                $datea[] = $rowd['AttdDate'];
                $daya[] = $rowd['day'];
                $houra[] = $rowd['hourid'];$hhour ='';$day = '';
                while($prow = $query->fetch_assoc())
                {   
                    $date = $prow['AttdDate'];
                    $hhour = $prow['hhour'];
                    $day = $prow['dday'];
                    $hourid = $prow['hourid'];
                    $datea[] = $prow['AttdDate'];
                    $daya[] = $prow['day'];
                    $houra[] = $prow['hourid'];
                    //student table header
                    $th.= '<td class="dispdates"><span>'.$date.'<br>'.$hhour.'<br>'.$day.'</span></td>';
                }
                $th.= "<td>Present%</td></tr>";
                $Studenttblbodypresent.=$th."</thead>";

                while($prowstd = $querystd->fetch_assoc())
                {
                    //student list
                    //$Studenttblbody.= '<tr role="row"><td>'.$prowstd['deptno'].'</td><td>'.$prowstd['name'].'</td></tr>';
                    $TotStudents[] = $prowstd['deptno'];
                    $datei=$datea;
                    $dayi=$daya;
                    $houri=$houra;
                    $curStud = $prowstd['deptno'];

                    $countsql = "SELECT a.student_id as regno,
                    a.student_rollno AS rollno,
                    a.name,
                    a.deptno,
                    a.year,
                    branch.description as bdesc,
                    course.coursecode as ccd, 
                    users.firstname as ufn, 
                    users.lastname as uln,
                    course.description as ccdes 
                         , SUM(1)   AS tot
                         , SUM(a.present = 1) AS P
                         , SUM(a.present = 0 ) AS A 

                         , 100.0 
                         * SUM(a.present = 1)
                         / SUM(1) AS perpre

                         , 100.0 
                         * SUM(a.present = 0 )
                         / SUM(1) AS perabs 

                         FROM attendance a
                         LEFT JOIN branch on branch.id = a.branch
                         LEFT JOIN course on course.id = a.coursecode
                         LEFT JOIN users on users.id = a.user
                         where a.date BETWEEN '$from' AND '$to' AND
                         a.branch = $branchid and a.coursecode = $courseid and a.batch = $batchid 
                         AND a.active = 1 AND a.user = $usnid AND a.deptno = '$curStud'
                         GROUP BY a.student_id
                         ORDER BY a.student_rollno ASC";

                    $countquery = $conn->query($countsql);
                    $countrow = $countquery->fetch_assoc();


                    $perpre = $countrow['perpre'];
                    $h = array();
                    $da = array();
                    $d = array();
                    //$th = "";
                    $td = "<tr class='student'><th class = 'thead-present'>".$curStud."</th>";
                    for ($i=0;$i < $dateNo;$i++)
                        {
                            $h = $houri[$i];
                            $da = $datei[$i];
                            $d = $dayi[$i];
                            $b = $branchid;
                            $c = $courseid;
                            $ba = $batchid; 

                            $sqls = "SELECT *,deptno,AttdDate,p
                                        FROM
                                        (SELECT *,DAY(date) AS Day_c, 
                                        MONTHNAME(date) AS Month, 
                                        Year(date) AS Year_c,
                                        date(date) AS AttdDate,hour as h, day as dayorder,
                                        (CASE  WHEN present = 1 
                                            THEN ''
                                            WHEN present = 0 
                                            THEN 'A'
                                        END) AS p
                                        FROM attendance a 
                                        WHERE a.hour = $h AND a.date = '$da' AND a.day = '$d' AND a.branch = $b AND a.coursecode = $c 
                                        AND a.batch = $ba AND deptno = '$curStud'
                                        ORDER BY student_rollno ASC 
                                        )
                                        as report 
                                        LEFT JOIN schedules on schedules.id = report.hour
                                        ORDER BY Month DESC, Year_c DESC,student_rollno ASC,AttdDate ASC";

                                        $querys = $conn->query($sqls)or die($conn->error);
                                        while($prows = $querys->fetch_assoc())
                                        {   

                                            $td.= "<td>".$prows['p']."</td>";
                                        }


                        }
                        $td.="<td>".$perpre."</td></tr>";
                        $Studenttblbodypresent.= $td;
                }



                echo json_encode(array('RepHdrtblbody'=>$RepHdrtblbody,
                                        'present'=>$Studenttblbodypresent,
                                        ));

        }       
        else{
            echo "You have not given attendance";
        }
}
?>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM