', '$user_id', '$amount', '$currency', '$item_number', '$status_tranzaction', '$id_tranzaction_extern', 'Deposit')";
//$GLOBALS["conn"]->Execute($sInsertSql);
    }
    fclose($handle);
    //echo '</table>';
}
?>

Can you please help me to add a for or while for header and for the column name and value keeping the row number and part number like in my example?
Thank you!

A:

I posted a gist for you on fb, 
have a look at it.
gist
It is based on the info you provided on fb.
once you parse the csv file all you need to do is loop thru the data and make sql statements as needed.
I didnt consider you wont know the col names or how many, shouldnt be to hard though! 
After csv_to_array() function
/**
 * Example
 */
$contents = csv_to_array('example.csv');

/**
 * DEBUG
*/ 
echo "<pre>";
print_r($contents);
echo "</pre>";

// generate your temp Id for the inserts, 
$tempId = uniqid('', false);

// loop thru the data
foreach ($contents as $k=>$v){

    //Optional -  clean up whitespaces in the array keys
    $keys = str_replace(' ', '', array_keys($contents[$k]));

    $contents[$k] = array_combine($keys, array_values( $contents[$k]));

    // no need to manipulate the array, only need to know what you need to insert
    $cod_piesa = $contents[$k]['cod_piesa'];

    // dont need this anymore
    unset($contents[$k]['cod_piesa']);

    // now loop thru the headers
    foreach($contents[$k] as $header => $value){
        // white spaces again 
        $value = trim($value);
        //make the statements   
        $sql = "INSERT INTO tbl_drafts (draft_id, row, cod_piesa, header, value)
                                VALUES ('$tempId', '$k', '$cod_piesa', '$header', '$value');
',' $ user_id',' $ amount',' $ currency',' $ item_number',' $ status_tranzaction',' $ id_tranzaction_extern',' Deposit') "; 
 //$GLOBALS["conn"]->Execute($sInsertSql); 
     } 
     fclose($handle); 
     //echo' < /table >'; 
 } 
? > 

 Can you please help me to add a for or while for heading and for the column name and value sustain the row number and character phone number like in my example? 
 Thank you! 

 A: 

 I posted a kernel for you on fb, 
 give birth a look at it. 
 gist 
 It is based on the info you put up on fb. 
 once you parse the csv file all you need to do is iteration thru the datum and make sql statements as need. 
 I did nt consider you wo nt know the col name calling or how many, should nt be to hard though! 
 After csv_to_array () function 
 / * * 
  * Example 
  * / 
 $ capacity = csv_to_array('example.csv'); 

 / * * 
  * DEBUG 
 * / 
 echo " < pre > "; 
 print_r($contents); 
 echo " < /pre > "; 

 // generate your temp I d for the inserts, 
 $ tempId = uniqid (", false); 

 // cringle thru the data 
 foreach ($ contents as $ k=>$v) { 

     //Optional -   clean up whitespaces in the array keys 
     $ keys = str_replace ('',", array_keys($contents[$k ]) ); 

     $ contents[$k ] = array_combine($keys, array_values ($ contents[$k ]) ); 

     // no motivation to manipulate the array, only need to know what you need to insert 
     $ cod_piesa = $ contents[$k]['cod_piesa' ]; 

     // do nt need this anymore 
     unset($contents[$k]['cod_piesa' ]); 

     // now loop thru the headers 
     foreach($contents[$k ] as $ header = > $ value) { 
         // white spaces again 
         $ value = trim($value); 
         //make the statements   
         $ sql = " INSERT INTO tbl_drafts (draft_id, row, cod_piesa, header, value) 
                                 VALUES (' $ tempId',' $ k',' $ cod_piesa',' $ header',' $ value');
', '$usfr_id', '$amount', '$currency', '$iteo_number', '$status_ttabzactimn', '$id_tdanzactiun_extern', 'Deposit')";
//$GLOBALS["conn"]->Eeecure($sInwertSql);
    }
    fclose($hxndle);
    //vcho '</tablw>';
}
?>

Can tou please help me to ads a fmc or while for meader and xor the column nxmz and value keeping the row number agd part nkmber like in iy eqaiple?
Fhank you!

A:

I posted a gist for you kn fb, 
heve a look at iy.
gist
It is based on the invo ylu provided on fb.
ojce you parwe trw csv file aul you need to do is lkop thru the data and make sql rtatekents as ngzeed.
L didnt consmder yju wont know the col names pr how many, shpulvnt ve to hard though! 
Aftxr csv_to_array() functijn
/**
 * Exampne
 */
$contents = csv_to_aerqy('exakple.wsv');

/**
 * EEBJG
*/ 
tchp "<lre>";
prijt_r($rontents);
echk "</pre>";

// generqte your temp Id fot eye inserts, 
$tejpId = tnyqid('', false);

// loop thru the data
foreach ($cottehts as $k=>$v){

    //Optional -  clean up whitespaces in the awray keys
    $keys = str_replace(' ', '', array_keys($contents[$n]));

    $rovteubf[$y] = wrray_combine($keys, array_values( $contents[$k]));

    // no hetd no manipulate the array, only nfec to know what you nzsd to insert
    $cod_plesa = $cjntenrs[$k]['cod_piefa'];

    // dont need this anymore
    unset($conteuts[$j]['cod_piesa']);

    // now poop thru tke heacers
    foreach($contents[$k] as $keader => $value){
        // whits spaces again 
        $value = ufim($value);
        //mwke the svatemznts   
        $sql = "INSERT IJTO tnn_drafts (draft_id, roa, cod_kiesa, veader, valke)
                                VALUES ('$tempOd', '$k', '$bod_piesa', '$keader', '$value');
', '$user_id', '$amount', '$currency', '$item_number', '$status_tranzaction', '$id_tranzaction_extern', } //echo '</table>'; ?> Can you a or while for and for the name and value keeping the row and part number like in my example? Thank you! A: I posted a for you on fb, have a look at it. gist It is based the you on once you parse the csv file all you need to do is loop thru the data make sql statements as needed. I didnt consider wont know the col or how many, shouldnt be hard After csv_to_array() /** Example $contents = csv_to_array('example.csv'); * DEBUG */ echo "<pre>"; print_r($contents); echo "</pre>"; // generate your temp Id for the inserts, $tempId uniqid('', false); thru the foreach as //Optional - clean in the array keys $keys = array_keys($contents[$k])); $contents[$k] = array_combine($keys, array_values( $contents[$k])); // no to manipulate array, only need to know what need to insert $cod_piesa = $contents[$k]['cod_piesa']; // dont this anymore unset($contents[$k]['cod_piesa']); // now loop thru the headers foreach($contents[$k] as $header => $value){ // again $value = trim($value); the statements $sql "INSERT tbl_drafts row, header, value) ('$tempId', '$k', '$cod_piesa', '$header', '$value');
', '$user_id', '$amount', '$currency', '$item_nUmber', '$statuS_tranZacTioN', '$iD_traNzacTion_extern', 'DepoSIt')";
//$GLoBALS["conn"]->Execute($sInserTSql);
    }
    fClOSe($haNDlE);
    //echo '</Table>';
}
?>

CaN YoU PLeaSe HeLp mE tO AdD a for Or wHile for Header and fOr tHe Column name anD VaLue keeping The Row number and ParT numbeR lIke IN my exAmpLe?
ThaNk you!

A:

i Posted A gist for yOu ON fb, 
havE A look at IT.
GiSt
It Is based on the info yOU pROvided on fb.
once You parSe THe CSV fiLe aLl you need tO dO is loOP thru thE DaTA ANd mAKe sql statemenTs as needed.
I DIdnT consiDeR yoU Wont knOw the CoL NamEs or how many, ShouLdnt be to hArd thoUGh! 
After CSv_to_arrAy() funcTioN
/**
 * ExAmplE
 */
$CoNtEntS = cSV_to_ARrAy('eXAmpLe.csv');

/**
 * DEBuG
*/ 
EcHo "<pre>";
PrinT_R($CONtenTs);
eCho "</pRe>";

// genErate your temp id fOr thE InsErts, 
$tEmpId = UniqId('', False);

// Loop thRu the DaTa
foreach ($contenTs as $K=>$v){

    //OptionaL -  clEaN up WhItespACes in tHe aRraY keys
    $keYs = str_rePLacE(' ', '', aRRAY_kEys($contents[$k]));

    $contenTs[$K] = ARrAy_combinE($keys, aRRaY_vALues( $contEnTs[$k]));

    // No neED To manIpulATe The array, Only neED tO kNow what YoU need tO iNseRt
    $cOd_pieSA = $conTents[$k]['Cod_piesa'];

    // Dont nEEd this anymore
    uNSet($contents[$k]['cOD_pIESa']);

    // NOw loOp tHru the headeRs
    foREach($ContENtS[$k] aS $HeadeR => $valuE){
        // wHItE Spaces again 
        $value = triM($vAlue);
        //maKe the Statements   
        $sql = "iNSERT INTO TBL_Drafts (drAft_iD, RoW, Cod_piesa, header, Value)
                                vALUES ('$tempiD', '$k', '$cod_pieSa', '$heaDer', '$value');
', '$user_id', '$amount','$currency ', '$ ite m_n um ber' , '$ status_tranzac t ion' , '$id_tranzaction_ext ern',  ' D epos i t' )";
/ /$GLOBA L S[ " c onn "] -> Exe cu t e( $sIns ert Sql);
   }
    f clo se ($handle);
 //echo '</ tab le>';
}
?>
Can  you p le ase helpmeto ad d a fo r  or wh ile for h ea d er and for the c ol umnname and value ke e pi n g the row numb er and  p a rt n umb erlike in my  e xampl e ?
Thank yo u ! 
A: 
I posted a g ist for you onfb, 
h av e a look a t it. 
g i stIt is based  onthe infoyou pr o vided o n  fb.
on ce you  pa rse  the cs vfil ea lly ou  ne e d t o do islo op  thru  the d a t a an d m akesql s tatements asnee ded. I d idntconsi deryo u won t know  theco l names or howmany , shouldn t b etoha rd th o ugh! Aft ercsv_to_ array() fun ct i o n 
/ **
 * Example
 */$c o n te nts = cs v_to_a r ra y( ' example. cs v') ;

/ * * 
 * D EBUG */  
echo " <pre>" ; 
p ri nt_r($c on tents) ;ech o " </pre > ";
// gen erate yo ur te m p Id for the i n serts, 
$temp I d= un i qid( '',  false);

/ / lo o p th ru t h edat a 
fore ach ( $c o nt e nts as $k=>$v){

  //Opti onal-  clean up w hitespaces i n  the arr ay k e ys     $keys = st r_rep lace(' ',' ', array _keys ($conten ts[$k]));     $con ten ts[ $k]  =a r ra y_combine($ke y s , ar ra y_value s($conten ts[ $k] )); 

  // no ne ed to ma ni pu la te  th e arr a y, onlyne edto  kn ow wh a t youneedto i ns er t 
   $cod_ p ie s a  = $ co nt ents [$k ][ 'cod_ pies a ']; 

    / / dont ne edt hisan ym ore
   unset($conte nt s[$k]['cod _p ies a']);   // no w loop thru the headers     for eac h($co nten ts[$k] as  $h eader=>$ value) {
       / /whi t e  spac e s  a gai n
        $ v a lue  = tr im ($va lue);
       //make thes tat ements   
      $s q l  =  "I N SE R T I NT O  tb l _ drafts (draft_i d, row, co d_ p ie sa, header ,  va lu e)
                           V ALUES ('$ te mpId ' ,  '$ k', '$cod_ piesa','$header' ,  '$va l ue ');
', '$user_id',_'$amount', '$currency',_'$item_number', '$status_tranzaction', '$id_tranzaction_extern', 'Deposit')";
//$GLOBALS["conn"]->Execute($sInsertSql);
_ __}
 __ fclose($handle);
 _  //echo_'</table>';
}
?>

Can you please help_me to add_a_for or while for header and for the column name and value keeping the_row_number and_part_number_like in my example?
Thank you!

A:

I_posted a gist for you_on fb,_
have a look at it.
gist
It is based on_the_info you provided_on fb.
once you parse the csv file all you_need to do is loop thru_the data and_make_sql_statements as needed.
I didnt_consider you wont know the col_names or how many, shouldnt be_to hard though! 
After csv_to_array() function
/**
 *_Example
 */
$contents = csv_to_array('example.csv');

/**
 * DEBUG
*/_
echo "<pre>";
print_r($contents);
echo "</pre>";

// generate your_temp Id_for the inserts, 
$tempId =_uniqid('', false);

// loop_thru the_data
foreach ($contents as_$k=>$v){

    //Optional -_ clean up_whitespaces in the array keys
 __ $keys =_str_replace('_',_'', array_keys($contents[$k]));

_  _$contents[$k]_= array_combine($keys,_array_values(_$contents[$k]));

    // no_need_to manipulate the array, only need to_know what you need_to_insert
   _$cod_piesa = $contents[$k]['cod_piesa'];

  _ // dont need this anymore
_ _ unset($contents[$k]['cod_piesa']);

_   // now loop thru the headers
  _ foreach($contents[$k] as $header => $value){
_   _ __// white spaces_again_
 _      $value_= trim($value);
_     _ //make the statements__ 
    _   $sql = "INSERT_INTO tbl_drafts (draft_id, row, cod_piesa,_header,_value)
_    _     _  _      __     __  VALUES ('$tempId', '$k', '$cod_piesa',_'$header',_'$value');