thinkphp 导入excel表到数据库中去的时候,为什么我的只能导最后一行?
这是要导入的Excel表:这是结果:这是代码://保存导入数据$this->save_import($data);}publicfunctionsave_import($...
这是要导入的Excel表:
这是结果:
这是代码:
//保存导入数据 $this->save_import($data); } public function save_import($data) { $Goods = M('dishes'); $add_time = time(); foreach ($data as $k=>$v){ if($k >= 1){ $id=$v['A']; $info[$k-1]['id'] = $id; $cid=$v['B']; $info[$k-1]['cid'] = $cid; $sid=$v['C']; $info[$k-1]['sid'] = $sid; $name=$v['D']; $info[$k-1]['name'] = $name; $describe=$v['E']; $info[$k-1]['describe'] = $describe; $standard=$v['F']; $info[$k-1]['standard'] = $standard; $unit=$v['G']; $info[$k-1]['unit'] = $unit; $brand=$v['H']; $info[$k-1]['brand'] = $brand; $province=$v['I']; $info[$k-1]['province'] = $province; $city=$v['J']; $info[$k-1]['city'] = $city; $county=$v['K']; $info[$k-1]['county'] = $county; $price=$v['L']; $info[$k-1]['price'] = $price; $jhprice=$v['M']; $info[$k-1]['jhprice'] = $jhprice; $addtime=$v['N']; $info[$k-1]['addtime'] = $addtime; $cate_custom=$v['O']; $info[$k-1]['cate_custom'] = $cate_custom; $brand_custom=$v['P']; $info[$k-1]['brand_custom'] = $brand_custom; $oldid=$v['Q']; $info[$k-1]['oldid'] = $oldid; //$info[$k-1]['add_time'] = $add_time; //print_r($info);exit; $result = $Goods->add($info[$k-1]); } } if($result){ $this->success('产品导入成功', 'Caipin/index'); }else{ $this->error('产品导入失败'); } //print_r($info); }}
求大神解答!!!!!!! 展开
这是结果:
这是代码:
//保存导入数据 $this->save_import($data); } public function save_import($data) { $Goods = M('dishes'); $add_time = time(); foreach ($data as $k=>$v){ if($k >= 1){ $id=$v['A']; $info[$k-1]['id'] = $id; $cid=$v['B']; $info[$k-1]['cid'] = $cid; $sid=$v['C']; $info[$k-1]['sid'] = $sid; $name=$v['D']; $info[$k-1]['name'] = $name; $describe=$v['E']; $info[$k-1]['describe'] = $describe; $standard=$v['F']; $info[$k-1]['standard'] = $standard; $unit=$v['G']; $info[$k-1]['unit'] = $unit; $brand=$v['H']; $info[$k-1]['brand'] = $brand; $province=$v['I']; $info[$k-1]['province'] = $province; $city=$v['J']; $info[$k-1]['city'] = $city; $county=$v['K']; $info[$k-1]['county'] = $county; $price=$v['L']; $info[$k-1]['price'] = $price; $jhprice=$v['M']; $info[$k-1]['jhprice'] = $jhprice; $addtime=$v['N']; $info[$k-1]['addtime'] = $addtime; $cate_custom=$v['O']; $info[$k-1]['cate_custom'] = $cate_custom; $brand_custom=$v['P']; $info[$k-1]['brand_custom'] = $brand_custom; $oldid=$v['Q']; $info[$k-1]['oldid'] = $oldid; //$info[$k-1]['add_time'] = $add_time; //print_r($info);exit; $result = $Goods->add($info[$k-1]); } } if($result){ $this->success('产品导入成功', 'Caipin/index'); }else{ $this->error('产品导入失败'); } //print_r($info); }}
求大神解答!!!!!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询