cleidirigoni
(usa Linux Mint)
Enviado em 23/01/2014 - 14:58h
Não to conseguindo fazer a soma total das tabelas de um aplicativo.
seria o (total_entrada)T.Entrada, (total_saida) T.Saida, (total_saldo)T.Saldo
segue a baixo o codigo fonte.
<div id="tabela">
<table width="968" height="10" border="0" cellspacing="0" bordercolor="#E6E6E6">
<tr>
<td width="500" colspan="2" style="border-right:1px solid #CCC;"></td>
<td align="center" width="150" colspan="1" bgcolor="#EEEEEE" style="border-right:1px solid #CCC;">
<strong>T.Entrada: </strong>R$: <?=number_format($total_entrada,2,",", ".")?>
</td>
<td align="center" width="150" bgcolor="#EEEEEE" colspan="1">
<strong>T.Saida: </strong>R$: <?=number_format($total_saida,2,",", ".")?>
</td>
<td align="center" width="150" bgcolor="#EEEEEE" colspan="1">
<strong>T.Saldo: </strong>R$: <?=number_format($total_saldo,2,",", ".")?>
</td>
</tr>
<tr>
<td background="img/back_tabela.jpg" class="bordaright" width="100"> Data</td>
<td background="img/back_tabela.jpg" class="bordaright" width="350"> Histórico</td>
<td background="img/back_tabela.jpg" class="bordaright" width="120"> Entrada</td>
<td background="img/back_tabela.jpg" class="bordaright" width="120"> Saida</td>
<td background="img/back_tabela.jpg" width="150">Saldo</td>
</tr>
<?php
include'classes/conexao.php';
$cont=1;
$entrada = 0;
$saida = 0;
$total_entrada = 0;
$total_saida = 0;
$total_saldo = 0;
$select_caixa = DB::getConn()->prepare('SELECT * FROM `caixa` ORDER BY id DESC') or die ('erro');
$select_caixa->execute();
while($list=$select_caixa->fetch(PDO::FETCH_ASSOC)){
$total_entrada = $total_entrada + $list['valor'];
if($list['opcao']=='Entrada'){
$entrada += $list['valor'];
}else{
$saida += $list['valor'];
}
if($cont % 2 <> 0){
?>
<tr class="back" bgcolor="#F9F9F9">
<td class="bordaright">
<?
echo $data_nova = implode(preg_match("~\/~", $list['data']) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $list['data']) == 0 ? "-" : "/", $list['data'])));
?>
</td>
<td class="bordaright"> <a href="visualizar/caixa.php?id=<?=$list['id']?>"><?=$list['historico']?></a></td>
<td class="bordaright">
<?
if($list['opcao']=='Entrada'){
echo 'R$ '.number_format($list['valor'],2,",", ".");
}else{
echo 'R$ 0,00';
}
?>
</td>
<td class="bordaright">
<?
if($list['opcao']=='Saida'){
echo ' R$ '.number_format($list['valor'],2,",", ".");
}else{
echo ' R$ 0,00';
}
?>
</td>
<td>
<?
if($list['saldo']<0){
echo '<font color="#FF0000">R$ '.number_format($list['saldo'],2,",", ".").'</font>';
}else{
echo 'R$ '.number_format($list['saldo'],2,",", ".");
}
?>
</td>
</tr>
<?
}else{
?>
<tr class="back" bgcolor="#EEEEEE">
<td class="bordaright">
<?
echo $data_nova = implode(preg_match("~\/~", $list['data']) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $list['data']) == 0 ? "-" : "/", $list['data'])));
?>
</td>
<td class="bordaright"> <a href="visualizar/caixa.php?id=<?=$list['id']?>"><?=$list['historico']?></a></td>
<td class="bordaright">
<?
if($list['opcao']=='Entrada'){
echo 'R$ '.number_format($list['valor'],2,",", ".");
}else{
echo 'R$ 0,00';
}
?>
</td>
<td class="bordaright">
<?
if($list['opcao']=='Saida'){
echo ' R$ '.number_format($list['valor'],2,",", ".");
}else{
echo ' R$ 0,00';
}
?>
</td>
<td>
<?
if($list['saldo']<0){
echo '<font color="#FF0000">R$ '.number_format($list['saldo'],2,",", ".").'</font>';
}else{
echo 'R$ '.number_format($list['saldo'],2,",", ".");
}
?>
</td>
</tr>
<?
}
$cont++;
}
?>
</table>
</div>