为什么不向我显示谁在场和谁不在?
文件位于此处.
该表的出勤人数为列:
attendance_id |时间戳|年|class_id |section_id |学生卡|class_routine_id |状态
attendance_id | timestamp | year | class_id | section_id | student_id | class_routine_id | status
状态值:(0个未定义,1个存在,2个不存在)
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> 推荐答案我认为我发现了您的问题.您错过了每个周期的结尾和其他几个括号.我不知道我是否可以将您的代码很好地组合在一起,但是至少现在应该写得更好.香港专业教育学院在这里把两个相同的代码与不同的语法",您可以看一下看起来更好.
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>我也建议您使用这种语法(我认为最好先回显html标签,然后再使用?php十次,但这是每个人的选择):
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>';更多推荐
显示学生的每月出勤报告
发布评论