PHP,MySQL:Attendence calendar

时间:2016-12-14 13:58:09

标签: php mysql

我正在关注日程表,我遇到了问题...如果我在DB中有多条记录,那么通过创建另一行等来破坏整个....你知道在这里可以做些什么让那件事有用吗?

我很确定这个问题是由循环造成的......无论如何我都迷失了。

daily_att2数据库表结构:

ID, User, Day. Month, Year, Event, Descr

用户数据库表结构:

id, username, fullname

PHP:

<?php
function calendar($month, $year){
echo "<title>".$year." - Workplan</title>";
include '../conntodb.php';
    echo "<table border=1>";
    echo "<tr>";//date
    echo "<td style='min-width:150px;' rowspan=2><center><b>".date('F', mktime(0, 0, 0, $month, 1))."</b></center></td>";
    for($day = 1; $day <= cal_days_in_month(CAL_GREGORIAN, $month, $year); $day++){
        echo "<td style='min-width:76px;'><center>".date("j", mktime(0, 0, 0, $month, $day, $year)).".".$month.".".$year."</center></td>";
    }
    echo "</tr>";//date

    echo "<tr>";//day
    for($day = 1; $day <= cal_days_in_month(CAL_GREGORIAN, $month, $year); $day++){
        if(date("D", mktime(0, 0, 0, $month, $day, $year)) == "Sat" OR date("D", mktime(0, 0, 0, $month, $day, $year)) == "Sun"){
            echo "<td bgcolor='#f47d42'><center>".date("D", mktime(0, 0, 0, $month, $day, $year))."</center></td>";
        } else
        echo "<td><center>".date("D", mktime(0, 0, 0, $month, $day, $year))."</center></td>";
    }
    echo "</tr>";//day

    echo "<tr>"; //attendance
    $query = "SELECT * FROM users ORDER by id";
    $results = mysqli_query($conn, $query);
            if (mysqli_num_rows($results) > 0) {
                while($row = mysqli_fetch_assoc($results)){ 
                echo "<td>".$row['fullname']."</td>";
                $username = $row['username'];

                for($day = 1; $day <= cal_days_in_month(CAL_GREGORIAN, $month, $year); $day++){

                $query2 = "SELECT * FROM daily_att2";
                $results2 = mysqli_query($conn, $query2);                       
                    if (mysqli_num_rows($results2) > 0) {
                        while($row2 = mysqli_fetch_assoc($results2)){
                            if($row2['user'] == $username AND $row2['day'] == $day AND $row2['month'] == $month AND $row2['year'] == $year AND $row2['event'] == "V"){ //Write "V" if vacation
                                echo "<td id=".$day." class='att_td'>V</td>";
                                    } else{
                                        echo "<td id=".$day." class='att_td'> </td>"; 
                                      } //Else create a blank td
                        } mysqli_free_result($results2);
                    } 
                }
                echo "</tr>"; 
                } mysqli_free_result($results);
            } //attendance

    echo "<tr>"; //Daily absence -- USELESS FOR THIS MOMENT
    echo "<td style='text-align: center;'>Daily team absence</td>";
    for($day = 1; $day <= cal_days_in_month(CAL_GREGORIAN, $month, $year); $day++){
        echo "<td id=".$day.".".$month.".".$year."> </td>";
    }
    echo "</tr>"; //Daily absence

echo "</table>";
}

for($months = 1; $months < 13; $months++){
    echo calendar($months, 2016);
    echo "<br>";
}

如果所选用户,日期和事件的记录等于&#34; V&#34;我希望在特定日期打印在页面上。希望你能理解......

非常感谢

0 个答案:

没有答案