更新表格,在laravel中给出未定义的偏移量

时间:2016-07-14 10:41:06

标签: php laravel laravel-4

我正在阅读一个文件,一旦阅读下面是csv_array数据:

Array (
    [0] => "1"
    [1] => "1468409102803"
    [2] => "dd 22"
    [3] => "test1"
    [4] => "test2"
    [5] => "test3"
    [6] => "testcity"
    [7] => "11111"
    [8] => ""
    [9] => ""
    [10] => "1234567"
    [11] => "GI230"
    [12] => "Eveready Reachargeable Torch DL91"
    [13] => "1"
)

以上数组更新订单表,如下所示:

DB::table('orders')->where('order_number',$csv_array[1])->update(array('ship_address1'=>$csv_array['3'],'ship_address2'=>$csv_array['4'],'ship_address3'=>$csv_array['5'],'ship_city'=>$csv_array['6'],'ship_zip'=>$csv_array['7']));

错误来了:

  

未定义的偏移量1

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

我认为你犯了数组键

的错误
DB::table('orders')->where('order_number',$csv_array[1])->update(array('ship_address1'=>$csv_array['3'],'ship_address2'=>$csv_array['4'],'ship_address3'=>$csv_array['5'],'ship_city'=>$csv_array['6'],'ship_zip'=>$csv_array['7']));

进入

DB::table('orders')->whereIn('order_number',$csv_array[1])->update(array('ship_address1'=>$csv_array[3],'ship_address2'=>$csv_array[4],'ship_address3'=>$csv_array[5],'ship_city'=>$csv_array[6],'ship_zip'=>$csv_array[7]));