Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite,
Estou com um quebra cabeças que parecia se super simples mas que só parece.
Funciona assim: existe uma tabela com os dias da semana e os produtos listados para compra.
Esse produto pode ser comprado com quantidades diferentes em dias diferentes.
No fim da linha de cada produto/semana aparece o sub-total das quantidades marcadas. Até aqui maravilha... o problema é que não consigo somar esses valores (subtotal) num total geral.
Será que alguem consegue me ajudar?
Segue o código até onde eu fiz.
Brigado e bjs...
<? $sqpd = query("select * from produto order by id_categoria, titulo asc");
$i=1;
$a=0;
while($tdp = $sqpd->fetch_assoc()):
if (($i % 2) == 1){ $fundo="#53301c"; $texto = "#ffb800"; }else{ $fundo="#FFFFFF"; $texto = "#47250F";}
$a = $a+1;
$i++;?>
<script>
function number_format( number, decimals, dec_point, thousands_sep ) {
var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
var d = dec_point == undefined ? "," : dec_point;
var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
function Calcula<?=$a?>()
{
document.getElementById('total<?=$a?>').value = document.getElementById('qtd<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('totala<?=$a?>').value =document.getElementById('qtdb<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('totals<?=$a?>').value =document.getElementById('qtdc<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('totald<?=$a?>').value =document.getElementById('qtdd<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('totalf<?=$a?>').value =document.getElementById('qtde<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('totalg<?=$a?>').value =document.getElementById('qtdf<?=$a?>').value * document.getElementById('valor<?=$a?>').value;
document.getElementById('subtotal<?=$a?>').value =
(parseFloat(document.getElementById('total<?=$a?>').value)) +
(parseFloat(document.getElementById('totala<?=$a?>').value)) +
(parseFloat(document.getElementById('totals<?=$a?>').value))+
(parseFloat(document.getElementById('totald<?=$a?>').value)) +
(parseFloat(document.getElementById('totalf<?=$a?>').value)) +
(parseFloat(document.getElementById('totalg<?=$a?>').value));
document.getElementById('stotal<?=$a?>').innerHTML = number_format(document.getElementById('subtotal<?=$a?>').value, 2,",",".");
}
</script>
<input type="hidden" name="valor<?=$a?>" id="valor<?=$a?>" value="<?=$opreco2?>"/>
<input name="qtd<?=$a?>" type="text" id="qtd<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();" />
<input name="qtdb<?=$a?>" type="text" id="qtdb<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();"/>
<input name="qtdc<?=$a?>" type="text" id="qtdc<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();" />
<input name="qtdd<?=$a?>" type="text" id="qtdd<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();" />
<input name="qtde<?=$a?>" type="text" id="qtde<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();" />
<input name="qtdf<?=$a?>" type="text" id="qtdf<?=$a?>" style="width:24px; height:15px; border:none; background-color:#cbc8c8;" size="5" onkeyup="Calcula<?=$a?>();" />
<input name="subtotal<?=$a?>" type="hidden" id="subtotal<?=$a?>" size="4" />
<input name="total<?=$a?>" type="hidden" id="total<?=$a?>" size="4" />
<input name="totala<?=$a?>" type="hidden" id="totala<?=$a?>" size="4" />
<input name="totals<?=$a?>" type="hidden" id="totals<?=$a?>" size="4" />
<input name="totald<?=$a?>" type="hidden" id="totald<?=$a?>" size="4" />
<input name="totalf<?=$a?>" type="hidden" id="totalf<?=$a?>" size="4" />
<input name="totalg<?=$a?>" type="hidden" id="totalg<?=$a?>" size="4" />
<div id='stotal<?=$a?>'></div>
<? endwhile?>
/applications/core/interface/imageproxy/imageproxy.php?img=http://www.panipao.com.br/layout.png&key=df35c7d3950f90eeddab74597648be2dcb669e2d6b7d01ab507bcbfed384c2fd" alt="layout.png" />
Carregando comentários...