<i id='1k3S1'><tr id='1k3S1'><dt id='1k3S1'><q id='1k3S1'><span id='1k3S1'><b id='1k3S1'><form id='1k3S1'><ins id='1k3S1'></ins><ul id='1k3S1'></ul><sub id='1k3S1'></sub></form><legend id='1k3S1'></legend><bdo id='1k3S1'><pre id='1k3S1'><center id='1k3S1'></center></pre></bdo></b><th id='1k3S1'></th></span></q></dt></tr></i><div id='1k3S1'><tfoot id='1k3S1'></tfoot><dl id='1k3S1'><fieldset id='1k3S1'></fieldset></dl></div>
  • <small id='1k3S1'></small><noframes id='1k3S1'>

  • <tfoot id='1k3S1'></tfoot>

      • <bdo id='1k3S1'></bdo><ul id='1k3S1'></ul>
      <legend id='1k3S1'><style id='1k3S1'><dir id='1k3S1'><q id='1k3S1'></q></dir></style></legend>

        在 yii 中从 csv 文件导入和保存数据

        Importing and saving data from csv file in yii(在 yii 中从 csv 文件导入和保存数据)

          • <small id='KRTYn'></small><noframes id='KRTYn'>

              <tbody id='KRTYn'></tbody>

            <tfoot id='KRTYn'></tfoot>
          • <i id='KRTYn'><tr id='KRTYn'><dt id='KRTYn'><q id='KRTYn'><span id='KRTYn'><b id='KRTYn'><form id='KRTYn'><ins id='KRTYn'></ins><ul id='KRTYn'></ul><sub id='KRTYn'></sub></form><legend id='KRTYn'></legend><bdo id='KRTYn'><pre id='KRTYn'><center id='KRTYn'></center></pre></bdo></b><th id='KRTYn'></th></span></q></dt></tr></i><div id='KRTYn'><tfoot id='KRTYn'></tfoot><dl id='KRTYn'><fieldset id='KRTYn'></fieldset></dl></div>
              <legend id='KRTYn'><style id='KRTYn'><dir id='KRTYn'><q id='KRTYn'></q></dir></style></legend>
              • <bdo id='KRTYn'></bdo><ul id='KRTYn'></ul>
                1. 本文介绍了在 yii 中从 csv 文件导入和保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我的 csv 文件的样子:

                  This is what my csv file looks like:

                  我有三个字段(import siteimport goodsimport status)来导入各自的数据.因此,如果用户点击import site,则只会保存站点名称,其余的不会保存,对于import goodsimport status 也是如此.

                  I have three fields (import site, import goods, import status) to import respective data. So if a user clicks on import site only sites name will get saved and the rest won't, similarly for import goods and import status.

                  site's 数据和 status' 数据保存在一个表中,而 goods 数据保存在其他表中.地点.如何将它们保存到多个表中?

                  The site's data and status's data are saved in a single table but the goods data is being saved in other table with respect to it's site. How do i save them into multiple tables?

                  推荐答案

                  我将分享一个简单的片段来解析 csv 文件,也许这可以帮助

                  I will share simple snippet to parse csv files, maybe this can help

                  $i=0; $keys=array();$output=array();
                          $handle=fopen($filename, "r");
                          if ($handle){
                               while(($line = fgetcsv($handle)) !== false) {
                                  $i++;
                                  if ($i==1) {
                                     $keys=$line;
                                  }
                                  elseif ($i>1){ 
                                      $attr=array();
                                      foreach($line as $k=>$v){
                                          $attr[$keys[$k]]=$v;
                                      }
                                      $output[]=$attr;
                                  }    
                               }
                              fclose($handle);
                          }
                  

                  这将完成这项工作,我总是在使用 csv 时使用它.为了使这个工作第一行必须包含键,例如:

                  This will do the job, i'm using it always when come to csv. To make this work 1st line must contain keys, for example:

                  import_site, import_goods, import_status
                  

                  在您的 $output 数组中,您将拥有带有键 $output["import_site"] 等的数据.

                  In your $output array you'll have data with keys $output["import_site"] and so on.

                  希望这会有所帮助.

                  这篇关于在 yii 中从 csv 文件导入和保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                  • <legend id='Ql1Wr'><style id='Ql1Wr'><dir id='Ql1Wr'><q id='Ql1Wr'></q></dir></style></legend>

                  • <tfoot id='Ql1Wr'></tfoot>
                      <tbody id='Ql1Wr'></tbody>
                  • <small id='Ql1Wr'></small><noframes id='Ql1Wr'>

                          • <bdo id='Ql1Wr'></bdo><ul id='Ql1Wr'></ul>
                            <i id='Ql1Wr'><tr id='Ql1Wr'><dt id='Ql1Wr'><q id='Ql1Wr'><span id='Ql1Wr'><b id='Ql1Wr'><form id='Ql1Wr'><ins id='Ql1Wr'></ins><ul id='Ql1Wr'></ul><sub id='Ql1Wr'></sub></form><legend id='Ql1Wr'></legend><bdo id='Ql1Wr'><pre id='Ql1Wr'><center id='Ql1Wr'></center></pre></bdo></b><th id='Ql1Wr'></th></span></q></dt></tr></i><div id='Ql1Wr'><tfoot id='Ql1Wr'></tfoot><dl id='Ql1Wr'><fieldset id='Ql1Wr'></fieldset></dl></div>