来自mysql

时间:2017-08-26 10:01:17

标签: php logic

This is table of attendance

如果想要显示出席学生资料页面。在日历的帮助下。如果学生出现在日期显示为绿色的日期,否则为红色。

2 个答案:

答案 0 :(得分:1)

我使用此代码,试一试

 <table id="user_cal_table" width="100%"  style=" table-layout: fixed;">
                                <tr>
                                    <th style="min-width:20%;"><strong>Sun</strong></th>
                                    <th style="min-width:20%;"><strong>Mon</strong></th>
                                    <th style="min-width:20%;"><strong>Tue</strong></th>
                                    <th style="min-width:20%;"><strong>Wed</strong></th>
                                    <th style="min-width:20%;"><strong>Thu</strong></th>
                                    <th style="min-width:20%;"><strong>Fri</strong></th>
                                    <th style="min-width:20%;"><strong>Sat</strong></th>
                                </tr>
                                <?php
                                    $today = getdate();
                                    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
                                    $maxday = date("t", $timestamp);
                                    $thismonth = getdate($timestamp);
                                    $startday = $thismonth['wday'];
                                    for ($i = 0; $i < ($maxday + $startday); $i++)  
                                    {
                                        if (($i % 7) == 0) 
                                            echo "<tr height='50px'>";
                                                if ($i < $startday) {
                                                    echo "<td class='invalid'></td>";
                                                }
                                                else {
                                                    $thisdate = ($i - $startday + 1)."-".$thismonth['mon']."-".$thismonth['year'];
                                                    $thisdate = strtotime($thisdate);
                                                    if($thisdate<=time()) {
                                                        if(isset($attendance[$thisdate]) && $attendance[$thisdate]=="Present")
                                                            { 
                                                                echo "<td class='Present'>"; 
                                                            }
                                                        else 
                                                            {
                                                                echo "<td class='absent'>"; 
                                                            }

                                                        ?>
                                    <b><span style="padding-left:2px"><?php echo $i - $startday + 1; ?></span></b>
                                    </div></td>
                                    <?php } else { ?>
                                    <td class="otherdate"><span style="padding-left:2px"><b>{$i - $startday + 1}</b></span> </td>
                                      <?php
                                            }
                                        }
                                        if (($i % 7) == 6) {
                                            echo "</tr>";
                                        }
                                    }
                                    for (; (($i % 7) != 0); $i++) {
                                        echo "<td class='invalid'></td>";
                                    }
                                ?>
                                    </tr>
                                  </table>

答案 1 :(得分:0)

    <?php 
if (isset($_GET['ym'])) {
        $ym = $_GET['ym'];
    }else{
        $ym = date('Y-m');
    }
    $timestamp = strtotime($ym,"-01");
    if ($timestamp === false) {
        $timestamp = time();
    }
    // today
    $today = date('Y-m-d', time());
    // h3 title
    $html_title = date('Y / F',$timestamp);

    $prev = date('Y-m', mktime(0,0,0,date('m', $timestamp)-1,1, date('Y', $timestamp)));
    $next = date('Y-m', mktime(0,0,0,date('m', $timestamp)+1,1, date('Y', $timestamp)));

    // days numbers
    $day_count = date('t', $timestamp);
    $str = date('w', mktime(0,0,0,date('m', $timestamp),1, date('Y', $timestamp)));
    // creating calander
    $weeks = array();
    $week = '';

    $week .= str_repeat('<td style="background-color: gray"></td>', $str);
    for ($day=1; $day <= $day_count ; $day++, $str++) { 
        $date = $ym.'-'.$day;
        if ($today == $date) {
            $week .= '<td class="today" style="vertical-align: middle;"><span>'.$day.'</span>';
        }else{
            $week .= '<td style="vertical-align: middle;">'.$day;
        }
        $week .= '</td>';

        if ($str % 7 == 6 || $day == $day_count) {
            if ($day == $day_count) {
                $week .= str_repeat('<td style="background-color:gray"></td>',6 -($str % 7));
            }
            $weeks[] = '<tr>'.$week.'</tr>';

            $week = '';
        }
    }
foreach ($weeks as $week) {
                    echo $week; 
                }
         ?>
this is the calander i have made. now how to check student is present or not