我无法显示多天缺席

时间:2014-12-05 05:28:06

标签: php

我的客户要求我从生物识别系统中显示他们的员工进出。我已经做过了,但它只显示了1天的数据。有人可以帮帮我..如果你能看到我在那里有很多代码而且它不能满足我的客户。我工作了将近一个月  这是我的代码..我是初学者。

<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
    if(isset($_REQUEST['startdate']) && isset($_REQUEST['enddate']))
    {

        $startdate = $_REQUEST['startdate'];
        $enddate = $_REQUEST['enddate'];
        $shiftdate = $_REQUEST['shiftdate'];
        $category= $_REQUEST['category'];
            $counterless = 0;
            $ncounter = 0;
            $count =0 ;
            $loop=0;
            $holder=0;
            $checker=0;
            $wala = 0;
            $present = 0;
            /*$_SESSION['nightname'] = array();
            $_SESSION['nighttime'] = array();
            $_SESSION['testname'] = array();
            $_SESSION['testtime'] = array();*/

            $con = mysqli_connect("localhost","root","","testingdb");
            $connect = mysqli_connect("localhost","root","","inoutchecking");

            mysqli_query($con,"delete from forprint");
            mysqli_query($con,"delete from absentforprint");

            $result = mysqli_query($con,"select * from wawart where Column_2 = '$startdate' order by Column_2 asc");
            if(mysqli_num_rows($result)>0)
            {
                while($row = mysqli_fetch_array($result))
                {
                    $time = $row['Column_3'];
                    $times = (int)($time);
                    $inout = $row['Column_4'];
                    $dates = $row['Column_2'];

                    if(($times <= 14 and $inout == '1') or ($times >=17 and $inout == '4'))
                    {
                        $_SESSION['testname'][$counterless] = $row['Column_1'];
                        $_SESSION['testtime'][$counterless] = $time;
                        $counterless++;
                    }
                    if(($times <= 20 and $times >= 15) and $inout == '1')
                    {
                        $_SESSION['nightname'][$ncounter] = $row['Column_1'];
                        $_SESSION['nighttime'][$ncounter] = $time;
                        $ncounter++;
                    }
                }
                $wala=1;
            }
            else
            {
                $wala=0;
            }


            if($category == 'dayshift')
            {
                $shift = 'Day Shift';
            }
            else if($category == 'nightshift')
            {
                $shift = 'Night Shift';
            }
            else
            {
                $shift = 'Night Shift and Day Shift';
            }
            echo "<label class='cat'>".$shift."</label>";
            echo "<label class='absent'>Absentees ".$startdate."</label>";
            if($category == 'dayshift')
            {
                mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
                echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th><th>DATE</th><th>IN</th><th>OUT</th></tr>";
                    for($x = 0; $x<$counterless;$x++)
                    {
                        $dempid  = $_SESSION['testname'][$x];
                        $day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
                        while($empinfo = mysqli_fetch_array($day))
                        {
                            $count++;
                            if($loop == '1')
                            {
                                echo "<td>NO OUT</td></tr>";
                                $loop=0;
                            }

                            $empid = $empinfo['empid'];
                            $empshift = $empinfo['shift'];
                            $name = $empinfo['lastname'];
                            $fname = $empinfo['firstname'];
                            $dept = $empinfo['department'];
                            $section = $empinfo['section'];
                            $checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
                            if($holder == $empinfo['empid'])
                            {
                                break;
                            }
                            echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
                            if(mysqli_num_rows($checking)>0)
                            {




                                while($row=mysqli_fetch_array($checking))
                                {
                                    $time = $row['Column_3'];
                                    $times = (int)$time;
                                    if($holder == $empinfo['empid'])
                                    {
                                        break;
                                    }
                                    else
                                    {
                                            $inout = $row['Column_4'];
                                            $time = $row['Column_3'];
                                            if($loop ==0)
                                            {
                                                $date =  $row['Column_2'];
                                                    echo"<td>".$row['Column_2']."</td>";
                                            }
                                            if($loop ==0 )
                                            {   
                                                if($inout == '1')
                                                {
                                                    $timein =  $time;
                                                    echo "<td>".$time."</td>";
                                                    $loop = 1;
                                                }
                                                if($inout == '4')
                                                {
                                                    $timein =  'NO IN';
                                                    $timeout = $time;
                                                    echo "<td><B>NO IN</td><td>".$time."</td></tr>";
                                                    $holder = $empinfo['empid'];
                                                    $loop = 0;
                                                }

                                            }
                                            else 
                                            {
                                                    if($loop =='1' && $inout == '4')
                                                    {
                                                        $timeout = $time;
                                                        echo "<td>".$time."</td></tr>";
                                                    }
                                                    if($loop =='1' && $inout == '1')
                                                    {
                                                        $timeout = 'NO OUT';
                                                        echo "<td><B>NO OUT</td></tr>";
                                                    }
                                                    $loop = 0;
                                                    $counter = 0;
                                                    $holder = $empinfo['empid'];
                                                    $checker = 2;


                                                    if($checker == 2)
                                                    {
                                                        mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$empid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
                                                        if (mysqli_connect_errno()) 
                                                        {
                                                              printf("Connect failed: %s\n", mysqli_connect_error());
                                                              exit();
                                                        }
                                                    }
                                            }

                                    }
                                }
                            }
                            ini_set('max_execution_time', 999999);
                        }
                    }
                echo"</table></div>";

                /*absentees*/
                if($wala == 1)
                {
                    $count = 0;
                    mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
                    echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
                        $day = mysqli_query($connect,"select * from nightshiftlist where shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
                            while($empinfo = mysqli_fetch_array($day))
                            {
                                $id = $empinfo['empid'];
                                $shift = $empinfo['shift'];
                                $lname = $empinfo['lastname'];
                                $fname = $empinfo['firstname'];
                                $date = $empinfo['datefrom'];
                                $dept = $empinfo['department'];
                                $section = $empinfo['section'];

                                for($x = 0; $x<$counterless;$x++)
                                {
                                    $dempid  = $_SESSION['testname'][$x];
                                    if($id == $dempid)
                                    {
                                        $present = 1;
                                        break;
                                    }
                                    else
                                    {
                                        $present = 0;
                                    }
                                    ini_set('max_execution_time', 999999);
                                }
                                if($present == 0)
                                {

                                        echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
                                        mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
                                        ini_set('max_execution_time', 999999);
                                    $count++;
                                }

                            }

                    echo"</table></div>";
                    echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";

                }
            }/*end of absentees*/

            if($category == 'nightshift')
            {
                mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
                echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DATE</th><th>DEPARTMENT</th><th>SECTION</th><th>IN</th><th>OUT</th></tr>";
                    for($x = 0; $x<$ncounter;$x++)
                    {
                        $dempid  = $_SESSION['nightname'][$x];
                        $day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift = 'nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
                        while($empinfo = mysqli_fetch_array($day))
                        {
                            $count++;
                            if($loop == '1')
                            {
                                echo "<td>NO OUT</td></tr>";
                                $loop=0;
                            }

                            $empid = $empinfo['empid'];
                            $empshift = $empinfo['shift'];
                            $name = $empinfo['lastname'];
                            $fname = $empinfo['firstname'];
                            $dept = $empinfo['department'];
                            $section = $empinfo['section'];
                            $checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
                            if($holder == $empinfo['empid'])
                            {
                                break;
                            }
                            echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
                            if(mysqli_num_rows($checking)>0)
                            {




                                while($row=mysqli_fetch_array($checking))
                                {
                                    $time = $row['Column_3'];
                                    $times = (int)$time;
                                    if($holder == $empinfo['empid'])
                                    {
                                        break;
                                    }
                                    else
                                    {
                                            $inout = $row['Column_4'];
                                            $time = $row['Column_3'];
                                            $dates = $row['Column_2'];
                                            if($loop ==0 && $inout == '1'&& $dates == $startdate)
                                            {
                                                $date =  $row['Column_2'];
                                                    echo"<td>".$row['Column_2']."</td>";
                                            }
                                            if($loop ==0  && $dates == $startdate)
                                            {   
                                                if($inout == '1')
                                                {
                                                    $timein =  $time;
                                                    echo "<td>".$time."</td>";
                                                    $loop = 1;
                                                }
                                                if($inout == '4')
                                                {
                                                    $timein =  'NO IN';
                                                    $loop = 0;
                                                }

                                            }
                                            else 
                                            {
                                                    if($loop =='1' && $inout == '4')
                                                    {
                                                        $timeout = $time;
                                                        echo "<td>".$time."</td></tr>";
                                                    }
                                                    if($loop =='1' && $inout == '1')
                                                    {
                                                        $timeout = 'NO OUT';
                                                        echo "<td><B>NO OUT</td></tr>";
                                                    }

                                                    $loop = 0;
                                                    $counter = 0;
                                                    $holder = $empinfo['empid'];
                                                    $checker = 2;
                                                    if($checker == 2)
                                                    {
                                                        mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$dempid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
                                                        if (mysqli_connect_errno()) 
                                                        {
                                                              printf("Connect failed: %s\n", mysqli_connect_error());
                                                              exit();
                                                        }
                                                    }
                                            }

                                    }
                                }
                            }
                            ini_set('max_execution_time', 999999);
                        }
                    }
                echo"</table></div>";
                /*absentees*/
                if($wala == 1)
                {
                    $count = 0;
                    mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
                    echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
                        $day = mysqli_query($connect,"select * from nightshiftlist where shift ='nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
                            while($empinfo = mysqli_fetch_array($day))
                            {
                                $id = $empinfo['empid'];
                                $shift = $empinfo['shift'];
                                $lname = $empinfo['lastname'];
                                $fname = $empinfo['firstname'];
                                $dept = $empinfo['department'];
                                $section = $empinfo['section'];
                                for($x = 0; $x<$ncounter;$x++)
                                {
                                    $dempid  = $_SESSION['nightname'][$x];
                                    if($id == $dempid)
                                    {
                                        $present = 1;
                                        break;
                                    }
                                    else
                                    {
                                        $present = 0;
                                    }
                                    ini_set('max_execution_time', 999999);
                                }
                                if($present == 0)
                                {

                                        echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
                                        mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
                                    $count++;
                                }

                                ini_set('max_execution_time', 999999);
                            }
                    echo"</table></div>";
                    echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";

                }
            }/*end of absentees*/

}   

?>

1 个答案:

答案 0 :(得分:0)

您正在执行的第一个sql select查询需要更正。您的select sql查询不考虑结束日期。请尝试以下查询

$result = mysqli_query($con,"select * from wawart where Column_2 >= '$startdate'  and Column_2 <= '$enddate' order by Column_2 asc");
相关问题