HELP Modifying excel to sql import script

Discussion in 'PHP' started by jigen7, Oct 8, 2007.

  1. #1
    i have gotten this script that imports excel to mysql data i need to modify this so that i only need to insert certain columns in the table how do i do that for example i only need to insert values in the userid and username fields??thx
    <?

    $fcontents = file ('./spreadsheet.xls');
    # expects the csv file to be in the same dir as this script

    for($i=0; $i<sizeof($fcontents); $i++) {
    $line = trim($fcontents[$i]);
    $arr = explode("\t", $line);
    #if your data is comma separated
    # instead of tab separated,
    # change the '\t' above to ','

    $sql = "insert into TABLENAME values ('".
    implode("','", $arr) ."')"; // i think this is the line need to be change
    mysql_query($sql);
    echo $sql ."<br>\n";
    if(mysql_error()) {
    echo mysql_error() ."<br>\n";
    }
    }
    ?>
     
    jigen7, Oct 8, 2007 IP