当前月份的PHP表,每行有日期

时间:2013-12-26 12:37:23

标签: php date calendar html-table timestamp

(见截图:)我想制作一张桌子,人们可以选择,在这个月的哪些日子里他们可以工作。他们每天可以选择3班(每天也可以选择不止一班)。

  1. col:day&当月的日期(不显示星期一和星期二) 2.-4.col:每个班次的复选框(每个复选框需要一个不同的名称,例如“131201Schicht1”
  2. Screenshot

1 个答案:

答案 0 :(得分:1)

在做任何php工作之前,你需要首先创建html表单,然后它将清楚需要由php生成什么,什么不是。这是我提出的HTML

<table border="1" width="100%">
    <tr>
        <td>Current month name</td>
        <td>Schicht 1</td>
        <td>Schicht 2</td>
        <td>Schicht 3</td>        
    </tr>
    <tr>
        <input type="check">
        <td>Sun. 1</td>
        <td><input type="checkbox" name="131201Schicht1" value=""></td>
        <td><input type="checkbox" name="131201Schicht2" value=""></td>
        <td><input type="checkbox" name="131201Schicht3" value=""></td>
    </tr>
</table>

然后使用以下PHP代码,我们获得填充表格所需的主要信息:

<?php
    //I added this to make it easy to add more shifts
    $number_of_shifts = 3;
    $now    =   time();
    $day    =   1; //Just a day counter
    $month  =   date('m', $now);
    $year   =   date('Y', $now);

    // number of days in this current month
    $days_in_month = cal_days_in_month(0, $month, $year);
?>

然后我们只需要运行以下代码来生成我们自己的表,其中包含遗漏特定日期等规则。

<?php
    $number_of_shifts = 3;
    $now    =   time();
    $day    =   1;
    $month  =   date('m', $now);
    $year   =   date('Y', $now);
    $days_in_month = cal_days_in_month(0, $month, $year);
?>
<html>
<body>
<table border="1" width="100%">
    <tr>
        <td><? echo date('F', $now).' '.$year; ?></td>
        <? for ($i=1; $i < $number_of_shifts+1; $i++)
        {
            echo "<td>Schicht $i</td>";
        }
        ?>
    </tr>
    <?php while ($day <= $days_in_month)
    {
        $timeForDay = mktime(0,0,0,$month, $day, $year);
        $dayName = date('D', $timeForDay);
        if($dayName != 'Mon' && $dayName != 'Tue')
        {
    ?>
        <tr>
        <?php
            echo '<td> '.$dayName.' '.$day.' </td>';
            $shiftId = date('ydm', $timeForDay);
            for ($i=1; $i < $number_of_shifts+1; $i++)
            {
                echo '<td><input type="checkbox" name="'.$shiftId.'Schicht'.$i.'" value=""></td>';
            }
        ?>
        </tr>
    <?
        }
    $day++;
    }
    ?>
</table>
</body>
</html>

这只是一段快速混乱的代码,您不应该在生产中使用它,我只是向您展示如何完成它并且未经过测试的技术!

相关问题