我有一个用于提交学生分数的表格,该表格应捕获会议ID(会议ID用于显示学校当前正在参加的会议,例如,2018/2019会议,2019/2020会议...)] >
在数据库的分数表中,将自动捕获并插入会话ID。当前,会话ID为14。
但是,由于未插入0而不是14的原因,这导致了很多问题
在“添加分数”表单中,仅在会话ID为14时才重新填充分数值。由于显示为0,因此值框仍为0
另外,我相信它会引起重复的问题。在表格编辑过程中,所有学生分数均重复。
Controller
function assigngradeAction() { for($i=0; $i<count($this->input->post('number')); $i++) { $data[]=array( 'section_id' => $this->input->post('section_id'), 'subject_id' => $this->input->post('subject_id'), 'class_id' => $this->input->post('class_id')[$i], 'student_id' => $this->input->post('student_id')[$i], 'session_id' => $this->input->post('session_id'), 'ca1' => $this->input->post('ca1')[$i], 'ca2' => $this->input->post('ca2')[$i], 'ca3' => $this->input->post('ca3')[$i], 'ca4' => $this->input->post('ca4')[$i], 'project' => $this->input->post('project')[$i], 'affective' => $this->input->post('affective')[$i], 'psychomotor' => $this->input->post('psychomotor')[$i], 'exam'=> $this->input->post('exam')[$i], 'tot_score'=> $this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i] + $this->input->post('exam')[$i], ); } $inserted = $this->primary_model->add1($data); if($inserted > 0) { $this->session->set_flashdata('msg', '<div class="alert alert-success">Grade Added successfully</div>'); //Echo back success json redirect('admin/primary/index'); } }
模型
public function add1($data) { // for each record insert foreach($data as $studentScore){ // get score $subjectId = $studentScore['subject_id']; $classId = $studentScore['class_id']; $sessionId = $studentScore['session_id']; $sectionId = $studentScore['section_id']; $studentId = $studentScore['student_id']; $score = $this->get_student_score($subjectId,$sessionId,$sectionId,$classId,$studentId); $studentScore['modified_at'] = date("Y-m-d H:i:s"); if(empty($score->id)){ $this->db->insert('scores_primary', $studentScore); }else{ $this->db->where('id', $score->id); $this->db->update('scores_primary', $studentScore); } // var_dump($studentScore, "\n >>>>>>>>", $score); } // $this->db->insert_batch('scores_primary', $data); // var_dump($this->db->error(), $_SERVER['SERVER_ADDR'] ); // $str = $this->db->last_query(); // echo "<pre>"; // print_r($str); return true; }
view
<?php }elseif($class_id >= 15 && $class_id <= 17){ ?>
<form action="<?php echo site_url('admin/primary/assigngradeAction') ?>" method="POST" id="formSubjectTeacher">
<?php echo $this->customlib->getCSRF(); ?>
<div class="row">
<div class="col-lg-3">
<input type="hidden" name="class" value="<?php echo $class_id; ?>">
<input type="hidden" name="subject_id" value="<?php echo $subject_id; ?>">
</div>
<div class="col-lg-4">
<h4><strong><?php echo $session_name; ?></strong></h4>
</div>
</div>
<br>
<hr>
<?php foreach($students as $student){ ?>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<label>Student Name</label>
<input type="hidden" name="number[]" value="">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="session_id" value="<?php echo $student->session_id; ?>">
<input type="hidden" name="student_id[]" value="<?php echo $student->student_id; ?>">
<input type="hidden" name="class_id[]" value="<?php echo $class_id; ?>">
<input type="text" value="<?php echo $CI->GetStudentNameWithID($student->student_id); ?>" class="form-control " readonly>
</div>
</div>
<div class="col-lg-1">
<label>ca1 </label>
<input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">
<input type="number" name="ca1[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca1: 0; ?>">
</div>
<div class="col-lg-1" id="t2">
<label>ca2</label>
<input type="number" name="ca2[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca2: 0; ?>">
</div>
<div class="col-lg-1" id="assg">
<label>ca3</label>
<input type="number" name="ca3[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca3: 0; ?>">
</div>
<div class="col-lg-1" id="exam">
<label>Exam</label>
<input type="number" name="exam[]" min="0" max="70" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->exam: 0; ?>">
</div>
<div class="col-lg-1">
<label>Total</label>
<output class="result"></output>
</div>
</div>
<?php } ?>
我有一个用于提交学生分数的表格,该表格应捕获会议ID(会议ID用于显示学校当前正在参加的会议,例如,2018/2019会议,2019/2020 ...
在view
的form
中,有两个名为input fields
↓↓的[C0
session_id