![]() |
Importing text file into MySQL?
I have a text file here, that I would like to import into a MySQL database (it's for an OScommerce webshop shop).
The text file looks like this: Code:
Artikelcode|Leverancierscode|Omschrijving|Adviesprijs|Bruto prijs|Voorraad|Artikelgroep|Prijsgroep|Kortings percentage|Selectiecode|Selectiecode omschrijving|UNSPSC code|Standaard nalevertijdThe web shop is using an other database, but as test I have created an empty MySQL named "testdb". The testdb does not have any tables in it.. Now how can I import this text file into an empty MySQL database? Any help appreciated! |
Hiya Edge
First you need to create tables where the data actually should be inputed to :) Then you can read data like this quite easily: Code:
AR8010BLK | AR8010BLK | RECESSED RAIL KIT FOR 600MM WIDE 19 BLACK | 128,75 | 110,21 | 2 | APC | 030000 | | CR3 | Cap.Rack 19 inch | 43172605 | 10Code:
$file = "/path/to/text/file.txt";Code:
$output = str_replace("\t|\t", "|", $data);Code:
$output = explode("\n", $output);Code:
foreach($output as $var) { |
Wow.. Thanks for that.
I was looking at the OScommerce database, and it looks like I need to do a lot to get this stuff imported to the correct tables. It looks like the tables: categories, categories_description, products_description, products_to_categories are the needed tables. (with a lot of rows in the tables :-/ ) I'm new to OScommerce, and as the OScommerce forum was down (it's working now again) I did not find an easy way to import a file like this.. Going over to the forum now to "maybe" find a tool to do this the easy way. |
Why does this not work?
No error show, but also no data added to the MySQL :/ The echo $Artikelgroep does show the Artikelgroep's. Basicly (for now) I want to dump all the "Artikelgroep"'s in to the database named: "testdb", table: "categories_description", field: "categories_name" Code:
<?phpCode:
CREATE TABLE `categories_description` ( |
Well, you did not select the mysql database anywhere in there :)
|
I've done some recoding, and it's now working:
Now all I need to find (for now) is NOT to INSERT the record when "Artikelgroep" is the same as the one before. The way it is now: "APC" is INSERT INTO 3 times.. Any suggestion (code snippet) for me :-) Code:
<?phpCode:
-- |
Okay.. Got the "same" problem fixed..
Please do not laugh of my code :-) Code:
if ( $Artikelgroep_tmp == $Artikelgroep ) |
Hi im a 17yrs old student and i learn a lot from this forum thank you so much,but i have a little problem here,i want my txtfile to upload on my page and link the txtfile content in the text-area line by line and import it on MySQL. :confused:
sorry for my poor English, please help thanks :D |
I don't understand what you try to do and I think it would be best to open a new thread for your problem.
|
| All times are GMT +2. The time now is 05:30. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.