更新多个选择的数据以获取多个值

时间:2018-02-12 10:37:26

标签: php codeigniter laravel-5.3

<select name="eng_country[]" class="form-control">

的print_r($ _ POST [&#39; eng_country&#39;]);出口;

through this i am getting output like:
 Array ( [0] => 1 [1] => 3 [2] => 2 ) 
after this i did :
foreach ($_POST['eng_country'] as $key => $value) {
                 $data = [   
                'table' =>  'tbl_worker_exp',
                'val'=>array(
                'country_id'=>$value),
                'where' =>  ['sub_id'=>$id]
            ];

             }
 $result=update($data); 
my table like:
    id  sub_id          data        
    1   2                 2                 
    2   2                 1                 
    3   2                 4                 
    4   1                 4     
  

我想改变我的数据字段,从我得到的价值   html选择选项,但在我的情况下,它的更新数据作为最后一次获取   价值..请帮我解决这个问题。

更新查询是:

function update($data)
    {
           $UpdateDB=DB::table($data['table'])
            ->where($data['where'])
            ->update($data['val']);
            return  $UpdateDB;
    }

1 个答案:

答案 0 :(得分:0)

foreach ($_POST['eng_country'] as $key => $value) {
             $data = [   
            'table' =>  'tbl_worker_exp',
            'val'=>array(
            'country_id'=>$value),
            'where' =>  ['sub_id'=>$id]
        ];
  $result=update($data); //keep the update function inside the loop
  }