【问题标题】:Updating multiple rows in one form submission Codeigniter在一个表单提交中更新多行 Codeigniter
【发布时间】:2017-10-08 14:52:59
【问题描述】:

搜索,谷歌搜索已经找不到相同案例的,

基本上我在一个表单中有一组多个类别,我想在一个表单提交上更新每个类别中的问题数。 以下是表格:

类别数量可以是动态的,每个问题文本框包含其名称=“问题”与类别ID合并为“问题12,问题13”等。

我知道 update_batch() ,但是我如何获取值并将它们放入数组中,因为它们可能是未知数。

如何在 CodeIgniter

中一次更新所有类别

【问题讨论】:

标签: php forms codeigniter


【解决方案1】:

我已经在 Controller 中使用 foreach 解决了这个问题

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;
    }

【讨论】:

    【解决方案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
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 2020-02-01
      • 2016-11-05
      • 1970-01-01
      相关资源
      最近更新 更多