-1

Here below my code. its working fine, only $itemsize is not inserting any data in db. Others filed are okay. FYI $itemsize will repeatedly insert in many row following $friendarray as $s666s this data.

    $friendslist = 
   "$s4s,$s6s,$s8s,$s10s,$s12s,$s14s,$sxss,$sss,$sms,$sls,$sxls,$sxxls";
        $friendarray = explode(",", $friendslist);
        $sizelists ="4,6,8,10,12,14,XS,S,M,L,XL,XXL";
        $size = explode(",",$sizelists);
        foreach ($size as $itemsize){
                                          echo "<li>$itemsize</li>";
                                           }

        for ($n = 0; $n < count($friendarray); $n++) {

        $friendidpush = "('".$style."','".$order."','".$color."','".$itemsize."','".$friendarray[$n]."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";
    }
        $query = "INSERT INTO freddyhipment (style, orderno, col, s4s, s6s, ctnqty, invoice, kcgmt, season, buyer, factory) VALUES ";
        $friendarray = explode(",", $friendslist);
        foreach ($friendarray as $s666s) {

            $query .= "('".$style."','".$order."','".$color."','".$itemsize."','".$s666s."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";

        }
        $query = substr($query, 0, -1); // remove trailing comma
  • 1
    Whats the crazy code finally produce `echo $query`? – Lawrence Cherone Sep 27 '17 at 21:13
  • Where is the code where it runs the insert query in database? – Felippe Duarte Sep 27 '17 at 21:20
  • Its a bit crazy, if you see my earlier question , you would understand.I need to get data from excel table to db in horizontal & vertical at the same time. Anyway I'm expecting some help. I'm stuck here. – Mehidy Hassan Rudro Sep 27 '17 at 21:21
  • this seems like a repost of your other question https://stackoverflow.com/q/46432063/1415724 where that "image of code" answer if yours https://stackoverflow.com/a/46449470/1415724 contains an image of that code here https://i.stack.imgur.com/9uWU8.jpg – Funk Forty Niner Sep 27 '17 at 21:30

2 Answers2

0

The foreach($size as $itemsize){ ends right after the echo statement. The variable $itemsize is not available after that. Maybe you have closed your foreach loop to soon.

Update: You could try this-

for ($n = 0; $n < count($friendarray); $n++) {
    $friendidpush = "('".$style."','".$order."','".$color."','".$size[$n]."','".$friendarray[$n]."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";
}

So instead of using $itemsize you use $size[$n]. That should give you what you are looking for.

Jeff Mattson
  • 394
  • 3
  • 9
0

Now its working fine with below code..

$friendslist = "$s4s,$s6s,$s8s,$s10s,$s12s,$s14s,$sxss,$sss,$sms,$sls,$sxls,$sxxls";
        $friendarray = explode(",", $friendslist);
        $sizelists ="4,6,8,10,12,14,XS,S,M,L,XL,XXL";
        $sizearray = explode(",",$sizelists);

        $frienduserarray = array();
        $sizeuserarray = array();

        for ($n = 0; $n < count($friendarray) && $n < count($sizearray); $n++) {


        $friendidpush = "('".$style."','".$order."','".$color."','".$sizearray[$n]."','".$friendarray[$n]."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";
        //array_push($frienduserarray $sizeuserarray, $friendidpush);

        }
        $query = "INSERT INTO freddyshipment (style, orderno, col, sizes, qty, ctnqty, invoice, kcgmt, season, buyer, factory) VALUES ";
        $friendarray = explode(",", $friendslist);
        $sizearray = explode(",", $sizelists);
        foreach ($friendarray as $index => $s666s) {
            $s888s = $sizearray[$index]; 
            $query .= "('".$style."','".$order."','".$color."','".$s888s."','".$s666s."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";    
        }
        $query = substr($query, 0, -1);

        $x++;

        if (mysqli_query($conn,$query)) {