我有一张表,根据学生的守时、整洁、专注或礼貌程度对他们进行评分。评分标准为1-5(评分标准:5=优秀,4=非常好,3=好,2=通过,1=一般(。
因此,如果一名学生的准时率被评为5,它会在数据库和视图中记录数字5。
但是,我更希望显示支票而不是数字。
复选框
控制器
public function TeacherRating()
{
$studentIds = $this->input->post('student_ids');
$session_ids = $this->input->post('session_ids');
$politenesses = $this->input->post('politenesses');
$punctualities = $this->input->post('punctualities');
$conducts = $this->input->post('conducts');
$honesties = $this->input->post('honesties');
$friendlies = $this->input->post('friendlies');
$neatnesses = $this->input->post('neatnesses');
$handwritings = $this->input->post('handwritings');
$gameses = $this->input->post('gameses');
$sportses = $this->input->post('sportses');
$drawings = $this->input->post('drawings');
$craftses = $this->input->post('craftses');
$musicalskillses = $this->input->post('musicalskillses');
$finalResults = [];
for ($i = 0; $i < sizeof($studentIds); $i++) {
$data['student_id'] = $studentIds[$i];
$this->db->query("DELETE FROM `teacher_ratings` WHERE student_id='".$studentIds[$i]."'");
$data['session_id'] = $session_ids[$i];
$data['politeness'] = $politenesses[$i];
$data['punctuality'] = $punctualities[$i];
$data['conduct'] = $conducts[$i];
$data['honesty'] = $honesties[$i];
$data['friendly'] = $friendlies[$i];
$data['neatness'] = $neatnesses[$i];
$data['handwriting'] = $handwritings[$i];
$data['games'] = $gameses[$i];
$data['sports'] = $sportses[$i];
$data['drawingpainting'] = $drawings[$i];
$data['crafts'] = $craftses[$i];
$data['musicalskills'] = $musicalskillses[$i];
$inserted = $this->Comment_model->TeacherRating($data);
array_push($finalResults, $inserted);
}
if ($finalResults > 0) {
$this->session->set_flashdata('success', 'Teacher Rating Added Successfully');
redirect('rate/rate_students');
}
}
这是我的评分表
<input type="number" max="5" min="1" name="politenesses[]" style="width: 100%;text-align: center;" value="<?php echo $student['politeness']; ?>"></td>
">显示的我的视图
<tr>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;">PUNCTUALITY</td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"> <?php echo $teacher_rating->punctuality; ?></td>
</tr>
我将基于示例数据制作一个非常简单的版本,希望您可以将其集成到实际代码中。这是一个非常常见的编程任务,所以它是一个很好的学习和放下的任务。PHP和HTML的混合有时会变得很难看,所以为了清晰起见,我个人更喜欢使用PHP的模板语法。如果您不喜欢它,也可以切换到echo
或使用正常的{}
PHP语法。
首先,我将创建一组属性和可能的分数。属性是一个人类可读标签和一个数组索引键名称的映射。在您的情况下,后者也可以是数据库列。
$attributes = [
'Punctuality' => 'punctuality',
'Honesty' => 'honesty',
];
$possibleScores = [1, 2, 3, 4, 5];
接下来,我将模拟你的数据库,为一个学生创建一个跨属性的分数。
$score = [
'punctuality' => 2,
'honesty' => 5,
];
最后,我将进行渲染。第一个循环只是呈现列标题。循环集一次对每个属性执行一个操作,然后对单元格每次进行一个评分,将单元格的当前值与内部循环的当前值进行比较,并在需要时弹出一个复选框。
<thead>
<tr>
<td></td>
<?php foreach ($possibleScores as $possibleScore): ?>
<th scope="col"><?php echo $possibleScore; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($attributes as $label => $arrayIndex): ?>
<tr>
<th scope="row"><?php echo $label; ?></th>
<?php foreach ($possibleScores as $possibleScore): ?>
<td class="checkbox">
<input
type="checkbox"
value="<?php echo $possibleScore ?>"
<?php if ($possibleScore === $score[$arrayIndex]): ?>
checked
<?php endif; ?>
/>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
上面的代码呈现了一个与下面的非常相似的表格
准时性 | ||