我如何计算在foreach循环中的当前出席率,其中attendnace_status == 1为现在

时间:2017-05-30 06:50:06

标签: php mysql codeigniter

如何计算attendnace_status == 1为现在的每个循环的总出席人数

<table id="" class="table table-bordered std_table">
    <thead>
        <tr>
            <th style="width:100%" class="col-sm-3">Name</th>                
            <?php foreach ($dateSl as $edate) : ?>                                
                <th class="std_p"><?php echo $edate ?></th>
            <?php endforeach; ?> 
            <th width="100%" style="width:100%" class="col-sm-3">Present</th>                       
        </tr>  
    </thead>      
    <tbody>
        <?php foreach ($attendance as $key => $v_employee): 
        $ctr = $ctr + $emp_attendance->attendance_status; ?>
            <tr>  
                <td style="width: 100%" class="col-sm-3"><?php echo $employee[$key]->first_name . ' ' . $employee[$key]->last_name . ' ' . $employee[$key]->employment_id ?></td>   
                <?php foreach ($v_employee as $v_result): ?>
                    <?php foreach ($v_result as $emp_attendance): ?>
                        <td>
                            <?php
                            if ($emp_attendance->attendance_status == 1) {
                                echo '<span  style="padding:2px; 4px" class="label label-success std_p">P</span>';
                            }if ($emp_attendance->attendance_status == 2) {
                                echo '<span  style="padding:2px; 4px" class="label label-success std_p">H</span>';
                            }if ($emp_attendance->attendance_status == '3') {
                                echo '<span style="padding:2px; 4px" class="label label-danger std_p">L</span>';
                            }if ($emp_attendance->attendance_status == '0') {
                                echo '<span style="padding:2px; 4px" class="label label-danger std_p">A</span>';
                            }if ($emp_attendance->attendance_status == 'H') {
                                echo '<span style="padding:2px; 4px" class="label label-info std_p">H</span>';
                            }
                            ?>
                        </td>
                    <?php endforeach; ?>   
                <?php endforeach; ?> 
                <td><?php
                    $ctr=0;
                    if ($emp_attendance->attendance_status == 1) {
                        $ctr++;
                        echo $ctr;
                    }
                 ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>

如何计算attendnace_status == 1为现在的foreach循环中的当前出勤总数

<th>Present</p>下我想要计算每个员工在foreach循环中的总出勤率。如果员工P状态25天,那么现在计数25.我已尝试上面的代码,但返回值

echo $ctr;

是1。

0 个答案:

没有答案