简体   繁体   English

更新表以在laravel中提供未定义的偏移量

[英]Updating the table giving undefined offset in laravel

I am reading a file and once reading below is the csv_array data: 我正在读取文件,并且在下面读取的是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"
)

Taking above array updating the orders table as below: 采取上述数组更新订单表,如下所示:

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']));

Error coming is: 出现错误是:

undefined offset 1 未定义的偏移量1

Try the following: 请尝试以下操作:

I thought you are made the mistake of array key 我以为你是数组键的错误

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']));

Into 进入

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]));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM