我是codeigniter的新手,我正在做以下的事情,但我沒有得到解決方案。在mysql codeigniter中插入和更新一個查詢
以下是一件一件的事情。
首先我從數據庫中獲取數據並通過foreach循環以表格格式顯示。 $''''''''''''''''''''''''''''''''); echo form_open('emp_hodm_update/update_hodm',$ attributes); ? >
日期 工作 合作伙伴 主任 時間 任務 狀態 行動 日期;?> 「類= 」「/> 工作;?>」 class =「」/> partner;?>「class =」「/> 主任;?> 「類= 」「/> 時間;?>」 類= 「」/> 任務;?> 狀態;?> 刪除通過點擊添加按鈕它會創建新的行所以我想更新舊的數據以及通過添加buttond插入到表中創建的新行數據。
但我沒有得到任何想法如何做到這一點。
控制器:
public function update_hodm(){
/* Checking the all validation of task form*/
//$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('work[]', 'Types of Work', 'required');
//$this->form_validation->set_rules('partner[]', 'Worked With', 'required');
$this->form_validation->set_rules('director[]', 'Director', 'required');
$this->form_validation->set_rules('time[]', 'No Of Hours', 'required');
$this->form_validation->set_rules('task[]', 'Task Details', 'required');
$this->form_validation->set_rules('status[]', 'Task Status', 'required');
if ($this->form_validation->run()) {
/* Taking the data from form*/
$todayDate = date('Y-m-d');
$work=$this->input->post('work');
$partner=$this->input->post('partner');
$director=$this->input->post('director');
$time=$this->input->post('time');
$task=$this->input->post('task');
$status=$this->input->post('status');
$count=count($this->input->post('work'));
$data =array();
for($i=0; $i<$count; $i++) {
$data[$i] = array(
'name' =>$this->session->userdata('emp_name'),
'date' =>$todayDate,
'work' =>$work[$i],
'partner' =>$partner[$i],
'director' =>$director[$i],
'time' =>$time[$i],
'task' =>$task[$i],
'status' =>$status[$i]
);
}
$add=$this->update->update_hodm($data,$todayDate);
/* Display Success message if data updated successfully in database*/
if($add){
$this->session->set_flashdata('hodm_form',"All HODM Data Inserted Successfully.");
$this->session->set_flashdata('hodm_form_class','alert-success');
}else{
/* Displaying the error message*/
$this->session->set_flashdata('hodm_form',"failed to add, Please Try again");
$this->session->set_flashdata('hodm_form_class','alert-danger');
}
return redirect('home');
} else {
$this->load->view('public/digital_hodm_view');
}
}
型號:
public function update_hodm($data,$todayDate){
$this->db->where('date',$todaydate);
$this->db->update_batch('task_form', $data,'date');//date is my table column name
return true;
}
- 請幫我找到解決方案。
預先感謝
爲什麼單擊添加按鈕時需要更新舊數據?只需在控制器中創建一個添加功能,並在添加按鈕被點擊時調用該功能 – Sultan
您實際上沒有提到問題所在!除了_但我沒有得知任何想法如何做到這一點。在這種情況下,解決方案是擊中書籍 – RiggsFolly
@蘇丹你沒有得到我。當我點擊添加按鈕,然後它創建同一列的新行空白。在填充新行並在舊行更改時,當我單擊提交按鈕時,它會進入帶有舊數據和新數據的表格 – xr33dx