0

! このようなチェックボックスを使用して現在の月の日付を印刷したい場合は、2013 年 1 月 3 日からチェックボックス [] 、2013 年 2 月 3 日 [] から月末まで、31 の日付と 31 のチェックボックスを使用します。配列 $isActive = $attendancelis['EmployeeAttendance']['is_active']; のチェックボックスの値。すべてのチェックボックスに $isActive 値が必要です。次はの出力ですprint_r($attendancelis);:

Array ( [EmployeeAttendance] => Array ( [id] => 5 [employee_id] => 8 [is_active] => 1 [date] => 2013-03-21 11:15:17 [day_month_year] => 2323123 ) ) Array ( [EmployeeAttendance] => Array ( [id] => 3 [employee_id] => 8 [is_active] => 1 [date] => 2013-03-12 17:47:03 [day_month_year] => 23213213 ) )
Array ( [EmployeeAttendance] => Array ( [id] => 0 [employee_id] => 8 [is_active] => 1 [date] => 2013-03-16 13:11:58 [day_month_year] => 324234324 ) ) -->

これは私のコードです:

<?php

$nrDaysCurrentMonth = date("t");    
for($dayNr = 1; $dayNr <= $nrDaysCurrentMonth; $dayNr++)
{
echo'<div style="width:300px;float:left;">';
echo  date(''.$dayNr.'-m-Y'); 
echo '<input name="frmEmployeeAttendance[]" type="checkbox" value="0" />'; 
foreach($attendanceList as $attendanceLis)
{
$isActivee = $attendanceLis['EmployeeAttendance']['date'];
$isActiveYM = strtotime(date('d-m-Y', strtotime($isActivee)));
$isActiveYMD = date('j', strtotime($isActivee)); 

if($dayNr==$isActiveYMD) {
$isActive = $attendanceLis['EmployeeAttendance']['is_active'];

if ($isActive){ 
echo '<input name="frmEmployeeAttendance[]" type="checkbox" checked=="checked" value="' . $isActive . '" />'; 
}
else { 
echo '<input name="frmEmployeeAttendance[]" type="checkbox" value="' . $isActive . '" />';
}       
}


}

echo '<br/>';
echo'</div>';  
}


?>
4

2 に答える 2

0
foreach($attendancelist as $attendancelis) {
}

必要に応じて、配列$attendancelistを2回繰り返します。

Array ( [EmployeeAttendance] => Array ( [id] => 5 [employee_id] => 8 [is_active] => 1 [date] => 2013-02-21 11:15:17 [day_month_year] => 2323123 ) ) Array ( [EmployeeAttendance] => Array ( [id] => 3 [employee_id] => 8 [is_active] => 1 [date] => 2013-03-12 17:47:03 [day_month_year] => 23213213 ) )
Array ( [EmployeeAttendance] => Array ( [id] => 1 [employee_id] => 8 [is_active] => 1 [date] => 2013-03-16 13:11:58 [day_month_year] => 324234324 ) ) -->

foreach($ attendancelist as $ attendancelis){}は、行の上を2回繰り返します。

ループ

for($i = 1; $i <= $no_of_days; $i++)
{
}

$ no_of_daysが1の場合、1回の反復を実行します。

これらの上記のループを組み合わせると...

    foreach($attendancelist as $attendancelis) {

    for($i = 1; $i <= $no_of_days; $i++)
    {
    //checkbox stuff here
    }

    }

反復を行います=($出席リスト(arrayitemsのnr)回)*$no_of_days。例:

  • 配列$attendancelistに1つのアイテムがあり、$ no_of_daysが1の場合、1つの(1 * 1)チェックボックスが表示されます。
  • 配列$attendancelistに2つのアイテムがあり、$ no_of_daysが1の場合、2つの(2 * 1)チェックボックスが表示されます
  • 配列$attendancelistに2つのアイテムがあり、$ no_of_daysが2の場合、4つの(2 * 2)チェックボックスが表示されます

また、フォーマットスキルにも取り組む必要があります。:-)これがどういうわけか役立つことを望みました...

アップデート:

<?php
$no_of_days = 10;

$attendancelist = array('a','b', 'c');

foreach($attendancelist as $attendancelis)
{


        for($i = 1; $i <= $no_of_days; $i++) {

                    ?>
                <div style="width:300px;float:left;">
                    INACTIVE<input type="checkbox" value="0" name="isactive"  />
                <?php echo $start = date('' . $i . '-m-Y'); ?>
                    <br/><br/><br/>         
                </div>
        <?php
        }

}
?>

上記のコードは、最初のループを3回繰り返します。(a、b、c)、反復ごとに10日間チェックボックスが表示されます。

再度更新: -各日付の値のみを表示したい場合......このようなもの...

<?php
$no_of_days = 10;
$attendancelist = array('a', 'b', 'c');

$outputCheckbox = array();

//Go through all days
for($i = 1; $i <= $no_of_days; $i++)
{

    //Show one checkbox for every date.
    foreach($attendancelist as $attendancelis)
    {
        $isActive = true; //Dummy

        if ($outputCheckbox[$i] == false) {

            if ($isActive) {
                echo '<input type="checbox" value="active"><br />';
            }
            else {
                echo '<input type="checbox" value="inactive"><br />';
            }
            $outputCheckbox[$i] = true;

        }
    }
    //--attendanceList loop

}
//-- days loop

?>
于 2013-03-22T08:12:15.540 に答える
0

ああ、私はあなたの質問を実際に理解していると思います! :-) たった2日かそこらしかかかりませんでした;-)

次の例は、当月の DAY 16 の下に 2 つのチェックボックスを出力します。最初の 1 つはオン (値 = 1) で、もう 1 つはオフ (値 = 0) で、day21 はオンのチェックボックス (値 = 1) を表示します。div などの書式設定は含まれていませんが、とにかく管理できると思います! :-)

<?php

//Example data
$attendanceList = array();
$attendanceList[0]['EmployeeAttendance'] = array('id' => 5, 'employee_id' => 8, 'is_active' => 1, 'date' => '2013-02-21 11:15:17', 'day_month_year' => 2323123);
$attendanceList[1]['EmployeeAttendance'] = array('id' => 3, 'employee_id' => 8, 'is_active' => 1, 'date' => '2013-03-16 17:47:03', 'day_month_year' => 23213213);
$attendanceList[2]['EmployeeAttendance'] = array('id' => 1, 'employee_id' => 8, 'is_active' => 0, 'date' => '2013-03-16 13:11:58', 'day_month_year' => 324234324);


//Go through all days for current month
$nrDaysCurrentMonth = date("t");    
for($dayNr = 1; $dayNr <= $nrDaysCurrentMonth; $dayNr++)
{
    echo 'Day: ' . $dayNr . '<br />';       //Show nr of current date once

    //Go through attendancelist and check where nr of dates match. 
    //Where they match, show checkboxes with active or not.
    foreach($attendanceList as $attendanceLis)
    {

        //Get this iterations date and get the number of day and put it into $isActiveYMD
        $isActivee = $attendanceLis['EmployeeAttendance']['date'];
        $isActiveYM = strtotime(date('d-m-Y', strtotime($isActivee)));
        $isActiveYMD = date('j', strtotime($isActivee)); //Day of month without leading zeros

        //Compare day of month with days loop value ($dayNr). If date from 
        if($dayNr==$isActiveYMD) {

            $isActive = $attendanceLis['EmployeeAttendance']['is_active'];

            if ($isActive) {
                echo '<input name="frmEmployeeAttendance[]" type="checkbox" checked=="checked" value="' . $isActive . '" /><br />'; 
            }
            else {
                echo '<input name="frmEmployeeAttendance[]" type="checkbox" value="' . $isActive . '" /><br />';
            }       
        }
        //--compare day of month...
    }
    //--attendanceList loop
    echo '<hr />';
}
//-- days loop

?>
于 2013-03-23T22:20:45.660 に答える