为什么我表中的会话ID更改为0



我有一个提交学生成绩的表格,该表格应该包含会话id(会话id用于显示学校当前正在进行的会话,例如2018/2019会话、2019/2020会话…(

会话表

在数据库中的分数表中,会话id会被自动捕获并插入。当前,会话id为14。

会话id

然而,由于未知的原因,插入了0而不是14。这导致了很多问题

  1. 在添加分数表单中,只有当会话id为14时,才会重新填充分数值。现在,由于它显示0,值框保持0

  2. 此外,我认为这会导致重复问题。在表格编辑过程中,学生的所有分数都是重复的。

控制器

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; 
}

视图

<?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 } ?>

viewform中,有两个名为session_idinput fields↓↓

  1. <input type="hidden" name="session_id" value="<?php echo $student->session_id; ?>">

  2. <input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">

重复的字段可能会导致问题,请检查哪个字段正确值,然后丢弃另一个。如果两个字段都有错误的值,然后检查值初始化的位置,这样这就是在PHP中调试的方式。

相关内容

  • 没有找到相关文章

最新更新