How to import CSV data to MySQL, specifying WHERE condition

Discussion in 'PHP' started by smrutik, Apr 22, 2009.

  1. #1
    Hi,

    How to import data to MySQL with a PHP program?
    I want to put some condition on the data that will be imported to the database;
    like I want to select the data (from CSV) of particular date only for column rcvd_date.

    I know pulling whole data in csv to the database table with "Load data Infile.."
    But I dont know how to put the WHERE condition.

    Pls guide.

    Thanks,
    Smruti.
     
    smrutik, Apr 22, 2009 IP
  2. kenfrank

    kenfrank Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sounds like you need your PHP script to parse (read and understand) the data, and you put the date filter in a loop that sends the INSERTs to the DB?
     
    kenfrank, Apr 22, 2009 IP
  3. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #3
    You have to use temporary table for that purpose. If you need to guide you just hit me on skype.

    Regards
     
    koko5, Apr 22, 2009 IP
  4. fourfingers

    fourfingers Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just upload the entire thing and then use sql to delete the dates you don't want.

    DELETE FROM mytable WHERE month < 10 AND day < 20
    DELETE FROM mytable WHERE month > 10 AND day > 22
     
    fourfingers, Apr 22, 2009 IP