【发布时间】:2016-08-03 11:01:29
【问题描述】:
我是codeigniter的新手,我正在做以下事情,但我没有得到解决方案。
下面一一介绍。
-
首先我从数据库中获取数据并通过foreach循环以表格形式显示。
<?php$attributes = array('class' => 'form-horizontal','id'=>'update_form'); echo form_open('emp_hodm_update/update_hodm', $attributes); ?>
日期 工作 伙伴 导向器 时间 任务 状态 行动 日期;?>" class="" /> 工作;?>" class="" /> 伙伴;?>" class="" /> 导演;?>" class="" /> 时间;?>" class="" /> 任务;?> 状态;?> 删除 通过单击添加按钮,它会创建新行,所以我想更新旧数据以及通过添加按钮创建的新行数据以插入表中。
但我不知道该怎么做。
控制器:
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 你没有明白我的意思。当我点击添加按钮时,它会创建同一列空白的新行。当我点击提交按钮填充新行并更改旧行后,它会进入包含旧数据和新数据的表格
-
更新是否有效?
-
@aman no update 也不行。
标签: php jquery html mysql codeigniter