import csv file into different tables in one database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hazelnut2705
    New Member
    • Dec 2006
    • 3

    import csv file into different tables in one database

    HI,

    I want to import data from csv files into more than one tables in php.i want to import the data into selected tables in the same database.

    Here is the output:
    1;2006-12-05;Sony;tv plasma;5;4500.0 0;4550.00;
    aaaaaaaaa;12;so ny;tv.jpeg;http ://;www.;57.00;

    The format of each line is:
    {products_statu s},{products_da te_available},{ manufacturers_i d},{products_na me},{products_t ax_class_id},
    {products_price },{products_pri ce_gross},{prod ucts_descriptio n},{products_qu antity},{produc ts_model},
    {products_image },{products_url },{products_wei ght}

    Here is my code:
    <?


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

    for($i=0; $i<sizeof($fcon tents); $i++) {
    $line = trim($fcontents[$i]);
    echo "$line<BR>" ;
    $arr = explode(";"", $line);
    echo "$arr";

    $sql = "insert into tablename values (". implode("'", $arr).")";
    mysql_query($sq l);
    echo $sql ."<br>\n";
    if(mysql_error( )) {
    echo mysql_error() ."<br>\n";
    }
    }
    ?>

    Thanks
  • seangates
    New Member
    • Dec 2006
    • 19

    #2
    Can you use phpMyAdmin? It has a nice import utility for CSV files.

    Sean

    Comment

    Working...