If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > help - from .txt to database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-05, 05:44
renaultbiler renaultbiler is offline
Registered User
 
Join Date: Feb 2005
Posts: 2
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?
Reply With Quote
  #2 (permalink)  
Old 02-10-05, 05:52
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-10-05, 07:14
marcelomarqueti marcelomarqueti is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 02-10-05, 11:48
renaultbiler renaultbiler is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On