SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populating DB from textfield

    Hello everyone,

    I was given a huge textfile (about 3000 lines), and I've been asked to create a MySQL db out of it. If I think about using phpmyadmin to insert each single information I start having headaches, so I was wondering if there is a way to create a php script able to handle this painful job for me. The textfield is formatted so that each line correspont to a user and their relative information is separated by commas:

    xxx, xxx, xxx, xxx, xxx
    xxx, xxx, xxx, xxx, xxx

    Do you think it's possible or I have to do this manually? Thank you in advance for the help!

  2. #2
    SitePoint Enthusiast thenk83's Avatar
    Join Date
    Sep 2005
    Location
    Hacienda Heights, CA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Americanloti.. I hope this gets you in the right direction! MAKE SURE that if the data is comma seperated in the split function add a comma... if its period seperated add a period...etc etc etc...

    Code:
    <?
    $open = fopen('file.txt, 'r');
    while(!feof($open)
    {
    	$line = $fgets($open, 2000);
    	list ($column1, $column2, $column3) = split('\,', $line);
    	//INCLUDE SQL CONNECTION BELOW
    	$sql = "INSERT INTO table SET column1='$column1..... etc";
    	mysql_query($sql);
    	$open++
    }
    fclose($open);
    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much!!
    It worked great! I can believe I almost thought I had to insert everything manually. Thank you again for the help!!

  4. #4
    SitePoint Enthusiast thenk83's Avatar
    Join Date
    Sep 2005
    Location
    Hacienda Heights, CA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet! And your welcome! Anytime!
    Mmmmm .NET...PHP...CF...
    AIM: THENK83
    MSN: thenk83@hotmail.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •