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

(See screenshot:) I want to make a table, where people can choose, on which days of the month they can work. They can choose between 3 shifts each day (also more than one each day possible).

  1. col: day & date of the current month (don't show Mondays & Tuesdays) 2.–4.col: checkboxes for each shift (each checkbox needs a different name, e.g. "131201Schicht1"

Screenshot

Before doing any php work, you need to create the html form first, then it'll be clear what needs to be generated by php and what wouldn't be. here's the HTML I came up with

<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>

Then using the following PHP code, we get the main pieces of info we need to populate the table with:

<?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);
?>

Then we just need to run the following code to generate our own table with rules like leaving out specific days, etc..

<?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>

This is just a quick messy piece of code, you shouldn't use that in production, I'm just showing you a technique on how it can be done and isn't tested !