Forum Moderators: coopster
The problem is everything is put into the first field. It doesn't seem to be able to put the correct data in the correct column.
In the text file the fields are seperated by spaces. Should I change this?
Thanks
FYI, usually commas or tabs are used to delimit fields.
You should set up your text file so that each new line indicates a new row in the database.
If you want to use php to load the data instead of mysql's import features, you could use something like:
<?php
//open the data file
$handle = fopen("test.csv", "r");
//read each row into an array called $data
while (($data = fgetcsv($handle, 1000, ",", " "))!== FALSE) {
//build the query
$sql = "insert into test_table values(";
//each element of the array is added to the query
foreach ($data as $value) {
$sql .= "\"$value\",";
}
//cut off the last comma
$sql = substr($sql, 0, -1);
$sql .= ")";
//some error handling in case things go wrong
mysql_query($sql, $db) or die("Error in query $sql:" . mysql_error());
}
fclose($handle);
?>
best,
Dave
you could also do it using the command line using LOAD DATA [dev.mysql.com], which is what phpmyadmin does but it may be easier to do it manually.
It could also just be the options you are using.
[edited by: matthewamzn at 4:19 pm (utc) on Aug. 7, 2005]
ther has to be some options on the import that you haven't set correctly, 'FIELDS TERMINATED BY' needs to be set to a tab
something like
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'
this is the default behaviour of LOAD DATA INFILE
which means (from the link I provided above)
the defaults cause LOAD DATA INFILE to act as follows when reading input:
Also, look at the "Fields enclosed by" field. You should probably check the "OPTIONALLY" box.
Also, the example row you pasted above doesn't have any tabs or spaces -- I'm assuming you didn't make the same mistake in your txt file.
[edited by: dhardisty at 4:25 pm (utc) on Aug. 7, 2005]
Thanx in advance for any insight.
Jasper
I have the original Excell csv file on my hard disk, but how do I get it to replace the currenct messed up rows in my dictionary file? I had 350 words so far!
Jasper