drzfnr0275 2017-03-10 12:38
浏览 16
已采纳

显示学生的每月出勤报告

Why is it not showing me who is present and who is not?

The file are here.

The table is attendance with columns:

attendance_id | timestamp | year | class_id | section_id | student_id | class_routine_id | status

Status values: (0 undefined, 1 present, 2 absent)


<?php
                        $data = array();

                        $students = $this->db->get_where('enroll', array('class_id' => $class_id, 'year' => $running_year, 'section_id' => $section_id))->result_array();

                        foreach ($students as $row):
                            ?>
                    <tr>
                        <td style="text-align: center;">
                        <?php echo $this->db->get_where('student', array('student_id' => $row['student_id']))->row()->name; ?>
                        </td>
                        <?php
                        $status = 0;
                        for ($i = 1; $i <= $days; $i++) {
                            $timestamp = strtotime($i . '-' . $month . '-' . $year[0]);
                            $this->db->group_by('timestamp');
                            $attendance = $this->db->get_where('attendance', array('section_id' => $section_id, 'class_id' => $class_id, 'year' => $running_year, 'timestamp' => $timestamp, 'student_id' => $row['student_id']))->result_array();


                            foreach ($attendance as $row1):
                                $month_dummy = date('d', $row1['timestamp']);

                                if ($i == $month_dummy)
                                $status = $row1['status'];

                                 endforeach;
                            ?>

                            <td style="text-align: center;">
        <?php if ($status ==1 ) { ?>
                                    <i class="entypo-record" style="color: #00a651;"></i>
                        <?php  } if($status == 2)  { ?>
                                    <i class="entypo-record" style="color: #ee4749;"></i>
        <?php  } $status =0;?>


                            </td>
  • 写回答

1条回答 默认 最新

  • dongyuli0964 2017-03-10 13:09
    关注

    I think I found your problem. You missed the end of a for each cycle and few other brackets. I dont know if I put your code together in a good way but at least it should be written better now. Ive put two same codes here with "different syntax" you can take a look which looks better.

    <?php
    $data = array();
    
    $students = $this->db->get_where('enroll', array('class_id' => $class_id, 'year' => $running_year, 'section_id' => $section_id))->result_array();
    
    foreach ($students as $row):
        ?>
        <tr>
            <td style="text-align: center;">
                <?php echo $this->db->get_where('student', array('student_id' => $row['student_id']))->row()->name; ?>
            </td>
            <?php
            $status = 0;
            for ($i = 1; $i <= $days; $i++) {
                $timestamp = strtotime($i . '-' . $month . '-' . $year[0]);
                $this->db->group_by('timestamp');
                $attendance = $this->db->get_where('attendance', array('section_id' => $section_id, 'class_id' => $class_id, 'year' => $running_year, 'timestamp' => $timestamp, 'student_id' => $row['student_id']))->result_array();
            }
            foreach ($attendance as $row1):
                $month_dummy = date('d', $row1['timestamp']);
    
                if ($i == $month_dummy) {
                    $status = $row1['status'];
                }
            endforeach;
        endforeach;
        ?>
    
        <td style="text-align: center;">
            <?php if ($status == 1) { ?>
                <i class="entypo-record" style="color: #00a651;"></i>
            <?php } if ($status == 2) { ?>
                <i class="entypo-record" style="color: #ee4749;"></i>
            <?php } $status = 0; ?>
        </td>
    

    And also i suggest you using this syntax (i think its better to echo the html tags then using ?php ten times but its everyones choice):

    <?php
    
    $data = array();
    
    $students = $this->db->get_where('enroll', array('class_id' => $class_id, 'year' => $running_year, 'section_id' => $section_id))->result_array();
    
    foreach ($students as $row):
    
        echo '<tr>
            <td style="text-align: center;">' .
        $this->db->get_where('student', array('student_id' => $row['student_id']))->row()->name .
        '</td>';
        $status = 0;
        for ($i = 1; $i <= $days; $i++) {
            $timestamp = strtotime($i . '-' . $month . '-' . $year[0]);
            $this->db->group_by('timestamp');
            $attendance = $this->db->get_where('attendance', array('section_id' => $section_id, 'class_id' => $class_id, 'year' => $running_year, 'timestamp' => $timestamp, 'student_id' => $row['student_id']))->result_array();
        }
        foreach ($attendance as $row1):
            $month_dummy = date('d', $row1['timestamp']);
    
            if ($i == $month_dummy) {
                $status = $row1['status'];
            }
        endforeach;
    endforeach;
    
    echo '<td style="text-align: center;">';
    if ($status === 1) {
        echo '<i class="entypo-record" style="color: #00a651;"></i>';
    } else if ($status == 2) {
        echo '<i class="entypo-record" style="color: #ee4749;"></i>';
    }
    $status = 0;
    echo '</td>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog