Results 1 to 7 of 7
  1. #1
    Newbie
    Join Date
    January 18th, 2005
    Posts
    21
    Hello you guys, how are you all doing ?
    I'm in trouble you guys, I'm 90% sure that it's impossible to create a script that understands a csv file delimited by commas, I'll tell you why.

    Cj say that fields will be separated like this:


    GiftTree,http://www.gifttree.com,04/06/2004 12:20:40 PM,Garden Grace,anniversary flower flowers get thank well you,"Send a graceful basket of Asters, Lisianthus, Pompons, Queen Ann's Lace, and accenting greenery for that special occasion.",63,,,,, etc ......

    So the first problem, is to have commas inside "" , but I got over that.
    And after I've spent some hours on it, I found out that some fields are just like this:

    "glass vase.Say,"Hello" Approx. 15"" W x 15"" H",5657,,,,,USD,0.00,74.95

    So it's IMPOSSIBLE to know when the " really begins and when it really ends ? Correct ? How do I get that done ?

    I'm using php + mysql + apache, win and linux


    Tks a lot you guys

    Escobar

  2. #2
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR> How do I get that done ?
    <HR></BLOCKQUOTE>

    The absolute easiest way I can think of is to eliminate the problem at its source by having CJ send you tab-delimited files. That's what I did, and it saved me a world of frustration judging by yours and other comments I've seen!
    There is no knowledge that is not power. ~Hemingway

  3. #3
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by Demian:
    Cj say that fields will be separated like this:

    GiftTree,http://www.gifttree.com,04/06/2004 12:20:40 PM,Garden Grace,anniversary flower flowers get thank well you,"Send a graceful basket of Asters, Lisianthus, Pompons, Queen Ann's Lace, and accenting greenery for that special occasion.",63,,,,, etc ......
    <HR></BLOCKQUOTE>
    In all fairness, that is the correct format for CSV.
    You should able to set MySQL to import CSV without any hassles. I'm sure there are tutorials around that have the exact settings you need, whether you are using LOAD DATA INFILE or mysqlimport.

  4. #4
    Newbie
    Join Date
    January 18th, 2005
    Posts
    21
    Nobody did it using csv + , ??
    Anyhelp is welcome.

    Tks a lot

  5. #5
    Member mikew's Avatar
    Join Date
    January 18th, 2005
    Location
    southern California
    Posts
    60
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by Pete:
    In all fairness, that is the correct format for CSV.
    You should able to set MySQL to import CSV without any hassles. I'm sure there are tutorials around that have the exact settings you need, whether you are using LOAD DATA INFILE or mysqlimport. <HR></BLOCKQUOTE>

    Unfortunately many ISPs (mine included) will not allow mysql LOAD DATA or mysqlimport. Therefore a script in PHP, Perl or Python can be used. But you need some rules to do it:

    1 - If the first character of a field is a quote, search forward until the ending quote is found. A comma should follow the ending quote

    2 - If the first character of a field is not a quote (likely numeric data), search forward until an ending comma is found.

    Here's a piece of Perl logic that reads one record at a time from a CSV file and breaks a record into separate fields based on these rules. This works well for me on my Overstock.com feeds:

    <pre class="ip-ubbcode-code-pre">$i=0;
    while($item=&lt;&gt;) {
    next if($i++ == 0); # skip the first item, it's a header

    # process the list of fields
    for($start=0, $j=1; $j&lt;=23; ++$j) {
    # for the non-numeric fields, extract using the matching quotes, for numeric fields use the next comma
    if(substr($item,$start,1) == "\"") {
    $loc = index($item, "\"", $start+1); # find the matching quote
    ++$loc; # and then the comma that follows
    }
    else {
    $loc = index($item, ",", $start+1); # find the next comma (no quote!)
    }
    $field = substr($item,$start,$loc-$start); # extract field
    $start = $loc + 1; # reposition the start of $item

    # at this point $field contains a field and $j contains the position (1, 2, 3...) of the field in the record
    .
    .
    .
    }
    </pre>

    Hope this makes sense!

  6. #6
    ABW Veteran Student Heyder's Avatar
    Join Date
    January 18th, 2005
    Posts
    5,482
    Alz you gotta do is use myadmin and escape characters are ""

  7. #7
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    The answers are out there.
    Here is another, Python:

    http://www.python.org/doc/2.3.2/lib/module-csv.html

    Good Luck.

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Do you know linkshare merchants with csv data feeds ??
    By piotrekr in forum Rakuten LinkShare - LS
    Replies: 1
    Last Post: August 29th, 2011, 09:27 AM
  2. Csv To Rss Feeds
    By National Discount Stores in forum ShareASale - SAS
    Replies: 11
    Last Post: November 28th, 2008, 09:24 AM
  3. CSV and XSL feeds?
    By dreamerscove in forum ShareASale - SAS
    Replies: 4
    Last Post: February 12th, 2007, 04:01 PM
  4. Ready to use XML/csv data feeds
    By myref in forum Starting an Affiliate Program & Merchant Q&A
    Replies: 0
    Last Post: November 23rd, 2004, 12:08 AM
  5. xml/csv data feeds
    By myref in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: November 22nd, 2004, 10:20 AM

Posting Permissions

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