Please, I need a little help, I am trying to add the values returned by a foreach ($ getDesEsp as $ itemListaDesEsp): but I always add the last value. in this case I have 4 records but I always add the last one. I'll leave my code please ... Excuse me but it's the first time commenting so I do not know how my code will look beforehand thanks to who can help me.
/ Here is what more of my code /
foreach ($obtenerDesEsp as $itemListaDesEsp):
$precioCarro = $itemListaDesEsp['costo_promedio_producto'];
$stockCarro = $itemListaDesEsp['exist_actual_producto'];
?>
<script type="text/javascript">
function operacion() {caja = document.forms["sumar<?php echo $a++?>"].elements;
var numero1 = Number(caja["cajas<?php echo $b++?>"].value);
var numero2 = Number(caja["precios<?php echo $c++?>"].value);
caja["totales<?php echo $d++?>"].value = ( numero1 - numero2 );
console.log(caja["totales"]);
}
</script>
<form name="sumar<?php echo $e++?>">
<input type="text" name="caja" id="cajas<?php echo $f++?>" value="<?php echo $stockCarro ?>" onchange="operacion()">
<input type="number" name="precios" id="precios<?php echo $g++?>" class="form-control" value="1" style="width:60px;" min="1" max="<?php echo $stockCarro?>" placeholder="Cantidad" onchange="operacion()">
<input type="text" name="totales" id="totales<?php echo $h++?>">
</form>
<?php
endforeach;