1
I have the code below where I need to add the value of a column (Mysql) and the result of this sum, subtract by any value, example: 5000 and the result of this operation is passed to the PHP page.
My code:
<?php
$opcoes2 = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8');
$conexao2 = new PDO("mysql:host=".SERVER."; dbname=".DBNAME, USER, PASSWORD,          $opcoes2);
$sql2  = "SELECT SUM(valor_boleto) - 5000 FROM boleto";
$stm2 = $conexao2->prepare($sql2);
$stm2->execute();
while($row2 = $stm2->fetch())  {
$soma = $row2['sum(valor_boleto)'];
 }  
?>
HTML:
<html>
  <body>
   A Soma dos Números do Banco de Dados foi <?=$soma?>.
    <div id="chart_div"></div>
   </body>
 </html>
The error generated is:
Notice: Undefined index: sum(valor_boleto) in C: xampp htdocs grafico.php on line 77
The select is OK, I see console returns the right value.
If my column "valor_boleto" there are 3 fields of 5000, would add up 15000 and subtracting by 5000, should return a "echo" of 10000.
Grateful who can help.
Straight shot huh?? It worked! Thanks Neuber, hugs.
– user54154