//Ayuda amigos.. problemas al insertar registros a una BD mysql con php provenientes de un archivo de excel

<?php
  
    //Ayuda amigos.. al insertar registros a una tabla fac provenientes de un archivo de excel, 
  //no logro que me repita e  inserte el encabezado NumFac que esta en la celda A1 y idCliente B1
  
  for ($i=10;$i<=$filas;$i++){
    $_DATOS_EXCEL[$i]['cant'] = $objPHPExcel->getActiveSheet()->getCell('A'.$i)->getCalculatedValue();
    $_DATOS_EXCEL[$i]['detalle'] = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->getCalculatedValue();
    $_DATOS_EXCEL[$i]['precioU'] = $objPHPExcel->getActiveSheet()->getCell('C'.$i)->getCalculatedValue();
    $_DATOS_EXCEL[$i]['total'] = $objPHPExcel->getActiveSheet()->getCell('D'.$i)->getCalculatedValue();
    //mi problemas es al hacer que se repitan estos datos y se inserten
    // el numero de repeticiones dependera de los detalles que contenga la factura
    $_DATOS_EXCEL[$i]['NumFac'] = $objPHPExcel->getActiveSheet()->getCell('A1')->getCalculatedValue();
    $_DATOS_EXCEL[$i]['idCliente'] = $objPHPExcel->getActiveSheet()->getCell('b1')->getCalculatedValue();
    }       
    $errores=0;


foreach($_DATOS_EXCEL as $campo => $valor){
    $sql = "INSERT INTO fac  (cant,detalle,precioU,total,NumFac,idCliente)  VALUES ('";
    foreach ($valor as $campo2 => $valor2){
    $campo2 == "NumFactura" ? $sql.= $valor2."');" : $sql.= $valor2."','";
    }

    $result = mysqli_query($con, $sql);
    if (!$result){ echo "Error al insertar registro ".$campo;$errores+=1;}
    }   
  ?>


from Recent Questions - Stack Overflow https://ift.tt/331iFmU
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)