Ich möchte meine Daten aktualisieren, aber die Spalte Mark_Obtained wird nicht aktualisiert. Ich weiß nicht warum, habe ich etwas falsch in meinem Code?Codeignger Database Update Problem
Dies ist in meinem Controller-Code:
function marks($exam_id = '', $class_id = '', $subject_exam_id = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
if ($this->input->post('operation') == 'selection') {
$page_data['exam_id'] = $this->input->post('exam_id');
$page_data['class_id'] = $this->input->post('class_id');
$page_data['subject_exam_id'] = $this->input->post('subject_exam_id');
if ($page_data['exam_id'] > 0 && $page_data['class_id'] > 0 && $page_data['subject_exam_id'] > 0) {
redirect(base_url() . 'index.php?admin/marks/' . $page_data['exam_id'] . '/' . $page_data['class_id'] . '/' . $page_data['subject_exam_id'], 'refresh');
} else {
$this->session->set_flashdata('mark_message', 'Choose exam, class and subject');
redirect(base_url() . 'index.php?admin/marks/', 'refresh');
}
}
if ($this->input->post('operation') == 'update') {
$students = $this->db->get_where('enroll' , array('class_id' => $class_id , 'year' => $running_year))->result_array();
foreach($students as $row) {
$data['mark_obtained'] = $this->input->post('mark_obtained_' . $row['student_id']);
$data['comment'] = $this->input->post('comment_' . $row['student_id']);
$this->db->where('mark_id', $this->input->post('mark_id_' . $row['student_id']));
$this->db->update('mark', array('mark_obtained' => $data['mark_obtained'] , 'comment' => $data['comment']));
}
$this->session->set_flashdata('flash_message' , get_phrase('data_updated'));
redirect(base_url() . 'index.php?admin/marks/' . $this->input->post('exam_id') . '/' . $this->input->post('class_id') . '/' . $this->input->post('subject_exam_id'), 'refresh');
}
$page_data['exam_id'] = $exam_id;
$page_data['class_id'] = $class_id;
$page_data['subject_exam_id'] = $subject_exam_id;
$page_data['page_info'] = 'Exam marks';
$page_data['page_name'] = 'marks';
$page_data['page_title'] = get_phrase('manage_exam_marks');
$this->load->view('backend/index', $page_data);
}
und das ist meine Ansicht:
<?php if($exam_id >0 && $class_id >0 && $subject_exam_id >0):?>
<?php
////CREATE THE MARK ENTRY ONLY IF NOT EXISTS////
$students = $this->db->get_where('enroll' , array(
'year' => $running_year , 'class_id' => $class_id
))->result_array();
foreach($students as $row):
$verify_data = array( 'exam_id' => $exam_id ,
'class_id' => $class_id ,
'subject_exam_id' => $subject_exam_id ,
'year' => $running_year,
'student_id' => $row['student_id']);
$query = $this->db->get_where('mark' , $verify_data);
if($query->num_rows() < 1)
$this->db->insert('mark' , $verify_data);
endforeach;
<input type="number" value="<?php echo $row2['mark_obtained'];?>" name="mark_obtained" class="form-control" >
Bitte helfen Sie mir, das Problem zu lösen.
Sie sollten das MVC-Konzept der Dinge aus der Codeigniter-Dokumentation hier lesen: https://www.codeigniter.com/userguide2/. – coderodour