1

わかりました、申し訳ありませんが、このコードはすべて混乱していますが、ユーザーがいつ何をするかをマークするための一種のカレンダーとして機能する html テキストエリアフォームを含むテーブルを作成しました。私は月曜日 - 日曜日を以下のコードに示していますが、カレンダーには合計で 4 週間または 4 セットの月曜日 - 日曜日があります。

PHPコードを使用して各月の日付を配置できるかどうか疑問に思っています。つまり、その時点での月に応じて、各行/列に 1 ~ 31 番目ですか?

私がこれを行う方法を教えていただければ、誰かの助けを本当に感謝します. ありがとう

<table width="100%" border="0" cellspacing="5" cellpadding="5">
      <tr>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Monday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Tuesday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Wednesday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Thursday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Friday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Saturday</th>
        <th width="11.5%" align="center" valign="middle" bgcolor="#EBEBEB" scope="col">Sunday</th>
       </tr>
        <tr>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_monday1.php" method="post" id="form1">         
     <textarea id="monday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="monday1" data-id="monday1" onkeyup="checkWordCount();"><?php echo $calendar['monday1'] ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_tuesday1.php" method="post" id="form1">            
     <textarea id="bio" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="tuesday1" data-id="tuesday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['tuesday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_wednesday1.php" method="post" id="form1">          
     <textarea id="wednesday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="wednesday1" data-id="wednesday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['wednesday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_thursday1.php" method="post" id="form1">           
     <textarea id="thursday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="thursday1" data-id="thursday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['thursday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_friday1.php" method="post" id="form1">         
     <textarea id="friday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="friday1" data-id="friday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['friday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_saturday1.php" method="post" id="form1">           
     <textarea id="saturday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="saturday1" data-id="saturday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['saturday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
        <th width="11.5%" height="55" align="left" valign="middle" bgcolor="#FFFFFF" scope="col"><form action="includes/mod_profile/mod_calendar/includes/change_sunday1.php" method="post" id="form1">         
     <textarea id="sunday1" style="width:79px; 
        margin-top:-31.1px;
        text-align:left;
        margin-left:-3px;
        height: 60px;
        position:absolute;
        z-index:90;
        resize: none; 
        border: hidden;" textarea name="sunday1" data-id="sunday1" onkeyup="checkWordCount();"><?php echo htmlspecialchars($calendar['sunday1']); ?></textarea>
    <input type="image" src="../PTB1/assets/img/icons/save-edit.png"class="cal-submit" width="12px" height="12px" name="submit" value="submit" id="submit"/>
    </form></th>
       </tr>
       <tr>
4

1 に答える 1

0

これにより、日付が正しい列に配置されます。必要なものを printCalendar() の内部ループに追加するだけです。

<?php
function getCalendarRows($year,$month)
{
    $result=array();
    $dt=new DateTime(sprintf('%04d-%02d-01',$year,$month));
    $weekDay=$dt->format('w'); //Weekday of the first
    $nextMonth=$month==12?1:$month+1;
    $nextMonthYear=$nextMonth==1?$year+1:$year;
    $dt=new DateTime(sprintf('%04d-%02d-01',$nextMonthYear,$nextMonth));
    $dt->sub(new DateInterval('P1D')); //last day of the month
    $row=array();
    $lastDay=$dt->format('j');
    //Start the first row with empty columns (false)
    for($i=0; $i<$weekDay; $i++)$row[]=false; 
    for($i=1; $i<=$lastDay; $i++)
    {
        $row[]=$i;
        $weekDay++;
        if($weekDay>6)
        {
            $result[]=$row;
            $row=array();
            $weekDay=0;
        }
    }
    if($weekDay>0) 
    {
        //Fill up the last row with empty columns
        for($i=$weekDay+1; $i<7; $i++) $row[]=false;
        $result[]=$row;
    }
    return $result;
}

function printCalendar($year,$month)
{
    $rows=getCalendarRows($year,$month);
    echo '
<table>
    <tr>
        <th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th>
    </tr>';
    foreach($rows as $row)
    {
        echo '
    <tr>';
        foreach($row as $weekday=>$date)
        {
            echo '
        <td width="50px" height="50px">'.($date===false?'':$date).'</td>';
//Put whatever else you want in here, you have $year, $month, $date, and $weekday (0 to 6)
//NOTE - if $date===false, this is an empty column
        }
        echo '
    </tr>';
    }
    echo '
</table>';
}
echo '
<h1>Jan 2013</h1>';
printCalendar(2013,01);
echo '
<h1>Feb 2013</h1>';
printCalendar(2013,02);
echo '
<h1>Mar 2013</h1>';
printCalendar(2013,03);
echo '
<h1>Dec 2013</h1>';
printCalendar(2013,12);
?>

これは phpfiddle にあります: http://phpfiddle.org/main/code/3vf-1z0 (sprintf が phpfiddle で動作しなかったため、DateTime コンストラクター呼び出しを変更しました)

于 2013-01-02T06:56:45.880 に答える