<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 文件导入和保存数据

        时间:2023-08-17

          • <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 文件导入和保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Yii 迁移,不创建表 下一篇:在 Yii 中从 MySQL 获取最后插入的 ID

                  相关文章

                2. <legend id='Ql1Wr'><style id='Ql1Wr'><dir id='Ql1Wr'><q id='Ql1Wr'></q></dir></style></legend>

                3. <tfoot id='Ql1Wr'></tfoot>
                4. <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>