Php 显示学生的每月出勤报告
为什么不告诉我谁在场,谁不在场? 文件是 该表包含以下列: 出勤|时间戳|年份|班级|部门|学生| id |类_例程_id |状态 状态值:(0未定义,1存在,2不存在)Php 显示学生的每月出勤报告,php,codeigniter,Php,Codeigniter,为什么不告诉我谁在场,谁不在场? 文件是 该表包含以下列: 出勤|时间戳|年份|班级|部门|学生| id |类_例程_id |状态 状态值:(0未定义,1存在,2不存在) 我想我发现了你的问题。您错过了每个周期的结束时间和其他几个括号。我不知道我是否以一种好的方式把你的代码放在一起,但至少现在应该写得更好。我在这里放了两个相同的代码和“不同的语法”,你可以看看哪个看起来更好 <?php $data = array(); $students = $this->db->get_
我想我发现了你的问题。您错过了每个周期的结束时间和其他几个括号。我不知道我是否以一种好的方式把你的代码放在一起,但至少现在应该写得更好。我在这里放了两个相同的代码和“不同的语法”,你可以看看哪个看起来更好
<?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十次,但这是每个人的选择):
也许您希望第二个endforeach符合最后的条件。我想你下次一定要说得更具体些。对不起,我什么都没录。
<?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>
<?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>';