Current location: Hot Scripts Forums » Programming Languages » PHP » Excel document containing records, need to save as a text file to upload to mysql


Excel document containing records, need to save as a text file to upload to mysql

Reply
  #1 (permalink)  
Old 06-04-04, 09:10 PM
bearslife bearslife is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Idaho
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation 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.

Thank you very much, take care
Mr. marshall
Reply With Quote
  #2 (permalink)  
Old 06-05-04, 03:24 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
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]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
Upload image & text to MYSQL --> AT THE SAME TIME? charliedhq PHP 1 02-20-04 02:57 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
File upload and path to mysql dalio PHP 0 08-12-03 08:24 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 10:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.