Excel document containing records, need to save as a text file to upload to mysql
Hi, I have a very fine question to ask today or tonight however it may be with you out there. I was wondering how I am going to convert my excel document into a text file that is readable in mysql. I have thousands of records that I don't want to do by hand and I know that this can be done. I have tried everything I can do for now, "BUT", I just can't figure this out, it's driving so crazy, and I know that this can't be too hard.
I have saved the excel file as a CSV (comma deliminated) file and it went through okay but I didn't or wasn't able to populate all my fields. It's like it didn't read right or something.
Is there any way possible I can turn this excel file into a text document that is readable for mysql and how do I make it put all the records in the right fields in mysql or phpmyadmin. I have already tried the upload the text link and did all that in phpmyadmin. Like I said , it only uploaded the first field and that was completely wrong. I don't know what happened. I am not completely illiterate, but for some reason this just doesn't want to populate all fields with the right record information.
I know that it needs to be in order and comma delimited. I just don't want to have to enter 5 million gazillion records if I don't have to.
My main question here is basically how am I going to save this Excel file as a mysql readable text file with all the appropriate commas and quotes and all that.
CSV ,as you said, is the solution!
but it depend on how you read its content!
if you can show some of the code it might help!
I run into the same problem when I wanted to take more than 20K books records, so I used this script:
PHP Code:
//first I read all lines and each in an array element!
$file = file('book.csv');
//then explode each line into parts and insert it
foreach ($file as $line) {
$p = explode(';', $line);
$insert = mysql_query("INSERT INTO books VALUES ('$p[0]', '$p[1]', '$p[2]', '$p[3]', '$p[4]', '$p[5]', '$p[6]', '$p[7]', '$p[8]')")or
die(mysql_error());
}
__________________ PHPSimplicity
We don't need a reason to help people - Zidane [FF9]