Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Unanswered: help - from .txt to database

    I have a large .txt file (standarized from supplyers) that looks like this (each row have the exact same width and some rows have no space at all..):

    1665730AUTOMAT S204M-C 1,6 0090000STK.1618
    1665731AUTOMAT S204M-C 10 0075000STK.1618
    1665732AUTOMAT S204M-C 13 0075000STK.1618
    1034811PR 500V 2X2,5/2,5 MM2 0003550MTR.1007


    I want to feed these rows into the table columns that i have created - itemno,description,price,pk,code
    where:
    1665730AUTOMAT S204M-C 1,6 0090000STK.1618

    each color represent the different columns datas as listed above

    - with this code i can print one row separated the way i want:

    $itemno=substr($linje,0,7);
    $description=substr($linje,7,27);
    $price=substr($linje,34,11);
    $pk =substr($linje,41,4);
    $code =substr($linje,45,4);


    - but i have no idea on how to put each rows datas into the mysql table columns, can anyone give me a solution?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use LOAD DATA INFILE to populate a table which has one column, VARCHAR(50)

    then use an INSERT/SELECT statement to populate your target table using SUBSTRING functions (note the first character position is 1)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2005
    Location
    Ribeirão Preto-SP-Brasil
    Posts
    2

    Thumbs up txt to database

    You can create one file information.sql with the instructions SQL, for example
    Code:
    insert into clients(name,date) values ('Marcelo','1985');
    When you conected in database execute this file
    Code:
    source information.sql
    This execute the sql codes in yor database.

  4. #4
    Join Date
    Feb 2005
    Posts
    2

    ..

    thank you for replying, i tried the LOAD DATA INFILE but it won't work at all, arent there any solution that works on this?

    Code:
    $query = "LOAD DATA INFILE 'dir/dir2/FILE.TXT' INTO TABLE data_number LINES STARTING BY '' TERMINATED BY '\n'";
    I'm not a programmer guru whem it comes to mysql - i've been trying for two days to get this sh*t to work now and i'm still not lucky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •