Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    import csv data to mysql using php

    Importing csv rows into mysql by using php

    one column E has 5 rows with one id
    How to save the 5 rows using the id

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Wrong forum, moving to PHP.
    Post your current code indicating where you are having a problem.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    GU-#528B,,Default,simple,Flower Girl Dresses,base,Fuchsia Baby Flower Dress,"New Style, Fuchsia Baby Flower Dress","New Style, Fuchsia Fancy Baby Dress",0.5,,,2,fuchsia-baby-flower-dress,4,,60,29.99,6/26/2012 0:00,,,5,1,,,,,,,,,,,,,,,,2,1,KG __long,KG __long,No,Fuchsia,,United States
    ,,,,Shop by Color,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Design,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Size,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Design/With Sleeves,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Size/Infant (0-24mo),,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Color/Fuchsia,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ,,,,Shop by Design/Baby Pageant Dresses,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


    the data should insert like gu-#528b,shop by color
    gu-#528B,shop by design like wise



    the code

    if (($handle = fopen( $csv_file, "r")) !== FALSE)
    {
    $header = fgetcsv($handle);

    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
    $sql ="INSERT INTO ctpdata (sku,category,name,description,price,specialprice,path,color,title) values('$data[0]','$data[4]','$data[6]','$data[7]','$data[16]','$data[17]','$con$data[58]','$data[43]','$data[137]')";
    }

    fclose($handle);
    }

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're not executing any sql commands here, you are only constructing the string. This one is probably no good either: '$con$data[58]'. You should also use mysqli or PDO and construct that into a prepared statement. You only have to bind once for the variables affected, and in the loop extract the array offsets into the appropriate variables and execute the statement. This will substantially reduce the overhead on large batch insertions.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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