[英]Codeigniter Database Update Issue
我想更新我的數據,但mark_obtained列不更新。 我不知道為什么,我的代碼有問題嗎?
這是在我的控制器代碼中:
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);
}
這是我的看法:
<?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" >
請幫我解決問題。
if ($this->input->post('operation') == 'update') {
$data['mark_obtained'] = $this->input->post('mark_obtained');
$data['comment'] = $this->input->post('comment');
$this->db->where('mark_id', $this->input->post('mark_id'));
$this->db->update('mark_obtained', $data); // ***MAYBE THIS WAS THE ISSUE****
$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_id'), 'refresh');
}
我指出了我更正的那一行,這可能是問題所在。 您說mark_obtained
列沒有更新,但是您實際上是在代碼中更新了一個稱為mark
的列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.