2

Searched, Googled already couldn't found one with same case,

Basically i have a set of multiple categories in one form, i want to update Number of questions in each category on one form submit. Following is the form: enter image description here

Number of categories can be dynamic, each Question TextBox contains its name = "question" merged with category ID and make it as "question12 , question13" etc.

I know about update_batch() , but how do i get values and put them in array as they can be of unknown number.

How do i update all categories at once in CodeIgniter

Noman Ali
  • 3,160
  • 10
  • 43
  • 77
  • Just check the accepted answer and You can pass your array like that. https://stackoverflow.com/questions/18465604/how-to-perform-a-batch-update-using-codeigniter-arrays – Yash Parekh May 10 '17 at 05:52

2 Answers2

2
$post = $this->input->post();
foreach($post as $key=>$value){
    if(strpos($key, "question") == 0){

        $category_id = substr($key, 8);

        //Use $category_id and $value in this loop to build update statement

    }
}
1

I have resolved this using foreach in Controller

foreach ($sample_settings as $sample) {
        $array['category_id'] = $sample['category_id'];
        $array['no_of_questions'] = $this->input->post('question'.$sample['category_id']);
        $batch_array[] = $array;
    }
Noman Ali
  • 3,160
  • 10
  • 43
  • 77