Adding elements from the server

0

Hello, I would like to know how to add values that pass me from the server. I created a system that controls the expenses / accounts, you register one of your accounts.

EX: Home Name: Car
Value: R $ 10,000 (per month)
Times: 5
Total: $ Value * Times. (R $ 50,000)


Name: House
Property Value: R $ 20,000 (per month)
Times: 5
Total: $ value * times. ($ 100,000)

TOTAL GENERAL ... (HOW TO DO IT?)

But now I want to add the total from the first 'account' to the total of the second 'account'. How do I do that ?
Code:

session_start();
 include("includes/conexa.php");
require_once 'init.php';
require 'check.php';
$voce = $_SESSION['user_name'];
$id = $_SESSION['user_id'];
include("includes/topotw.php"); 
echo "$voce e Seu ID: $id";

echo "";
include('includes/conexa.php');
$consulta = $PDO->query("SELECT * FROM  'contas'  WHERE id_pessoa LIKE '%".$id."%'");  
    while($linha = $consulta ->fetch(PDO::FETCH_ASSOC)) {  
      header('Content-Type: text/html; charset=utf-8');
     

Conta:

{$linha['nome_conta']}

Valor:

R$ {$linha['valor_conta']}

Vezes a Pagar:

{$linha['vezes_conta']}
$vl = $linha['valor_conta']; $vx = $linha['vezes_conta']; $total = $vl * $vx;

Total:

$total
}
?>
    
asked by anonymous 21.04.2017 / 18:55

1 answer

1

Create a variable outside the loop, and then within the loop, add up to each total, and display outside the loop:

session_start();
 include("includes/conexa.php");
require_once 'init.php';
require 'check.php';
$voce = $_SESSION['user_name'];
$id = $_SESSION['user_id'];

$totalGeral = 0;
include("includes/topotw.php"); 
echo "$voce e Seu ID: $id";

echo "";
include('includes/conexa.php');
$consulta = $PDO->query("SELECT * FROM  'contas'  WHERE id_pessoa LIKE '%".$id."%'");  
    while($linha = $consulta ->fetch(PDO::FETCH_ASSOC)) {  
      header('Content-Type: text/html; charset=utf-8');

Conta: 

{$linha['nome_conta']}


Valor: 

R$ {$linha['valor_conta']}


Vezes a Pagar:

{$linha['vezes_conta']}

      $vl = $linha['valor_conta'];
            $vx = $linha['vezes_conta'];
            $total = $vl * $vx;

Total: 

 {$total} 

$totalGeral += $total;

    } 


 TOTAL GERAL: <?php echo $totalGeral;?>
?>
    
21.04.2017 / 20:41