如何根据检索日期为新月创建新表?

时间:2015-02-02 10:52:47

标签: javascript php html mysql

我开发了一个应用程序,用于打印一个月内日期的员工状态。现在它正确地显示数据,但是我想为新月创建新表。如果新月的第一天发生,它会自动显示在新表中吗?有没有办法做到这一点? Appliaction的快照是:enter image description here 源代码:

<?php
            $name=$_SESSION['sess_username'];
            $dateofattendance=$_SESSION['sess_date'];
            $prevmonth=01;
            $status="absent";       
            $conn = new mysqli('localhost', '', '', 'test');
            if ($conn->connect_error)
            {
                die("Connection failed: " . $conn->connect_error);
            }            
            $sql1="SELECT `dateofattendance` FROM attendance ORDER BY `dateofattendance` DESC LIMIT 1";
            $result1 = $conn->query($sql1);
            if ($result1->num_rows > 0) 
            {
                while($row = $result1->fetch_assoc())
                {                   
                //$prevmonth= date("m", strtotime( $row["dateofattendance"] ) );
                }               
            }   
            $sql="SELECT dateofattendance,timeofattendance, status,timeofdeparture FROM attendance Where emp='$name' ORDER BY dateofattendance ASC ";
            $result = $conn->query($sql);           
            if ($result->num_rows > 0)         
            {                   
                    echo "<table class='table-bordered' border='black' cellpadding='5' ><thead> <tr><th> Date </th><th>IN</th><th>OUT</th><th>Status</th></tr></thead><tbody>";                 
                    while($row = $result->fetch_assoc())
                    {                           
                        $month= date("m", strtotime( $row["dateofattendance"] ) );  
                        if($month != $prevmonth)
                        {
                            echo "</tbody></table>";
                        }
                        // create the row
                        echo "<tr> <td>" . $row["dateofattendance"]. "</td><td>" . $row["timeofattendance"]."</td><td>" . $row["timeofdeparture"]."</td>";                          
                        if($row["status"]=='present')
                        {
                            echo "<td><span class='label label-success'>". $row["status"]."</span></td>";
                        }
                        else
                        {
                            echo "<td><span class='label label-danger'>". $row["status"]."</span></td>"; 
                        }"</tr>"; 


                     }                      
                    // close the last table
                    echo "</tbody></table>";        
            }   
            $conn->close();     
?>

1 个答案:

答案 0 :(得分:0)

你为什么要把这么简单的东西变得如此复杂。

在页面上设置下拉选项,如图所示:

enter image description here 然后,根据所选月份执行查询,然后仅显示所选月份的数据。