SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member wrinkled's Avatar
    Join Date
    Dec 2000
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Text File Import Question?

    Hello

    I'm taking my first stab at doing some mySQL stuff.... Our web provider doesn't allow access to the root, but does provide a interface called myphpadmin.

    Here is the poop! I'm trying to import text files to my table but I'm having a problems with the new line and delimiter concept. I'll explain

    In my test table I have a couple fields that I can import data to if I place the data for both fields on the same line in the text file. (Separated by a delimiter)

    Now, If I try and place the data for the two fields on seperate lines, mySQL assumes that each line is also a new record. So, the first data record (First line) goes into the first field, the next line of data (I would like to go into the second field) goes into the first field as well, but as a new record.

    Placing a delimiter at the end of the first line doesn't seem to make any difference...



    Do I have any hope of success.

    I guess I was hoping to avoid text files with one line that extends into infinity.

    Please feel free to comment if I haven't explained my situation in depth enought.

    Thanks...

    Dave
    David Wrinkle

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New line = new record

    As you have seen MySQL interprets each new line as a new record.
    So if you want to import your data as a text file you'll have to write the values of each set into one line, like this:

    Value1 [TABSTOP] Value2 [TABSTOP] Value3 [LINEFEED]
    Value1 [TABSTOP] Value2 [TABSTOP] Value3 [LINEFEED]
    ...

    Notice that [TABSTOP] is not be entered as a word - it's the delimiter you want to use. A tabstop (\t) is the standard for MySQL. Close each line with a [LINEFEED] - which simply means pressing the Enter-button.

    In real life the text-file would look like this:

    1 Boogie Yeah!
    2 Woogie Cool!

    etc.

    In phpMyAdmin you'll have the possibility to define which delimiter you have used in your text-file. phpMyAdmin assumes a ";" to be used. If you use tabstop instead enter "\t" as the delimiter.


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
  •