Jump to content

dumping csv lines into the database


esandra

Recommended Posts

This is the code that i'm using which works fine except that i have to make lots of changes in my xls file before i `save as` into a csv and any little mistake could cause the program not to work

foreach(explode($lineseparator,$csvcontent) as $line) { 

    $lines++; 

    $line = trim($line," \t"); 
     
    $line = str_replace("\r","",$line); 
     
    /************************************ 
    This line escapes the special character. remove it if entries are already escaped in the csv file 
    ************************************/ 
    $line = str_replace("'","\'",$line); 
    /*************************************/ 
     
    $linearray = explode($fieldseparator,$line); 
     
    $linemysql = implode("','",$linearray); 
     
    if($addauto) 
        $query = "insert into $databasetable values('','$linemysql');"; 
    else 
        $query = "insert into $databasetable values('$linemysql');"; 
     
    $queries .= $query . "\n"; 

    @mysql_query($query); 
} 

@mysql_close($con);  

this is how my actual csv looks like. I want this script to completely disregard any other things that sould not be dumoed into my database but i am clueless on how to do that

,,,,,,,,,

COLLECTION ON ARRASTRE/WHARFAGE,,,,,,,,,

,,,,,,,,,

"ENTRY DATE: AUGUST 20, 2010",,,2010 MP-AW NO:,,187,,,,

TOTAL COLLECTIONS: P ,,"20,610.32",,,,,,,

,,,,,,,,,

OR #:,313522 - 313550,,ARRASTRE,WHARFAGE,TOTAL,,,,

313522,0819MZ2010-94,TRIPLEX ENTERPRISES INC.,115.36,47.73,163.09,2010-08-20,187,,

313523,0819MZ2010-95,VC BERMEJO,120.37,48.33,168.70,2010-08-20,187,,

OR #:,313551 - 313572,,,,,2010-08-20,187,,

313551,0821ML2010-37,OCEANIC SALES,95.43,45.36,140.79,2010-08-20,187,,

313552,0819MZ2010-119,HI - TECH STEEL IND. CORP.,465.61,89.43,555.04,2010-08-20,187,,

,,,,,,,,,

,,TOTAL:,P,"20,610.32",,,,,

,,,,,,,,,

,,,,,,,,,

PREPARED BY: ____________________ ,,,,,,,,,

, JUDY ANNE A. BUDIAO,,,,,,,,

,,,,,,,,,

,,,,,,,,,

NOTED BY: __________________,,,,,,,,,

, ALBERTO O. LAZA,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,, ,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

,,,,,,,,,

 

 

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.