I am new on codeigniter,I am doing the following things but I didn't get the solution.
Here is the following things one by one.
First I fetch the data from database and display in table format by foreach loop.
<?php$attributes = array('class' => 'form-horizontal','id'=>'update_form'); echo form_open('emp_hodm_update/update_hodm', $attributes); ?>
date Work Partner Director Time Task Status Action date;?>" class="" /> work;?>" class="" /> partner;?>" class="" /> director;?>" class="" /> time;?>" class="" /> task;?> status;?> DeleteBy clicking add button it creates new rows SO I want to update the old data as well as new row data which is created by add buttond to insert into a table.
But I didn't get any idea how to do this.
Controller:
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'); } } Model:
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; } - Please help me to find the solution.
Thanks in advance