Welcome Guest, Not a member yet? Register   Sign In
Editing multiple rows of data at once
#1

[eluser]lmv4321[/eluser]
Hi all,

I have been looking for examples to see if it is possible to edit multiple rows of data from a table at once. I know how to do this with regular PHP and I can figure out how to display the rows in a view (using a simple loop and counter method), but I am having problems figuring out how to validate and save the data.

More details:
Using CI 1.6.3
The table has 3 fields - id, name, yes/no checkbox
There are 10 rows and I am not using pagination.

I know how to display all of the rows in a grid and I can edit them one by one, but what I would like is to display all of them and have the checkbox be editable on all so I can check and uncheck multiple rows all in one view.

If anyone could point me to an example or in the right direction, I would appreciate it.
#2

[eluser]Chris Newton[/eluser]
What I would do, is

1. set the form fields to something like
Code:
$checkboxname = "checkbox_". $id_number;
eg. checkbox_1, checkbox_2, checkbox_3, checkbox_4.

2. On the processing side of things, do something like

Code:
foreach ($item_id as $id)
{
    if ($this->input->post("checkbox_".$id);
    {
        $data_array['table_field'] = $this->input->post("checkbox_".$id);
        $this->load->model('my_model');
        $this->my_model->update($id,$data_array);
    }
}

Obviously that's a little on the simple side for an example, but basically what i do.
#3

[eluser]lmv4321[/eluser]
Thanks mahuti. That'll get me started.




Theme © iAndrew 2016 - Forum software by © MyBB