Menu

CSV to mysql ?

Help 2.02
2003-12-19
2003-12-19
  • ricardo roman

    ricardo roman - 2003-12-19

    saludos desde MEXICO :  )

    I have a file in format CSV, as I can drain it in the corresponding tables?

    I have reviewed file ITEM.PHP but I do not completely understand the tables in which there are to drain

    EXAMPLE :

    CSV file:

    Camiseta,Blanca,Algodn,1500
    Pantaln,Azul,Algodn,5000
    Jersey,Negro,Algodn,3500
    Malla,Azul,Algodn,3000
    Top,Blanco,Algodn,3400
    Correa,Negra,Cuero,3400
    Gorra,Colores,Algodn,1400
    Calcetines,Blancos,Algodn,500

    script PHP:

    <?php

    require("conexion.inc");
    $row = 1;

    $fp = fopen ("datos.scv","r");
    while ($data = fgetcsv ($fp, 1000, ","))
    {
       $num = count ($data);
      print " <br>";
      $row++;

      echo "$row.". $data[0]." ------------ ".$data[1]."-------".$data[3];
      $insertar="INSERT INTO almacen (articulo,color,material,precio) VALUES ('$data[0]','$data[1]','data[2]','data[3]')";
      mysql_query($insertar);
    }

    fclose ($fp);
    ?>

    if it indicates to me as they are the fields and in which tables are due to insert it is sufficient :  )
    (ITEM.PHP ,PRICE.PHP , ETC)

    THANKS ! ! ! !

     
    • Andreas Kansok

      Andreas Kansok - 2003-12-19

      Don't know and no idea what your posted PHP code is good for, but this way it dont work. So far is sure, because language dependent (name, description) informations are saved in *info tables and all other in * tables (i.e. iteminfo, item). So your script have to split informations from CSV into different tables and so on. Also price is in its own table (not language dependent, but currency ;-)

      phPay has a script for CSV import. I know, it isn't perfect, but close to solution.
      I.e. it splits lang.dep. informations for 1st property with explode("," ... ): /admin/importitem.inc.php line 74. It writes prices and other informations into corresponding tables.
      In line 25 of this file you find, which column has which function/content. may be you have to change your CSV, but that's not my problem ;-) OpenOffice will do this for you (sure not Excel ;-)
      I wrote a much, much better tool to import, but this isn't to use with phPay (yet).

      Greetings,
      Andreas.

       
    • ricardo roman

      ricardo roman - 2003-12-19

      script is an example:  I am going to read the lines that you say to see  that I can do,
      thank you very much

      ! ! ! !

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.