How to return the total value of items in a table?

-3

I want to know how to return the total value of items, I use mysqli to connect to the bank.

Table ec_despesas have the following fields: (more details of the structure in this image )

id, aba, status, nome, categoria, conta, valor, data
    
asked by anonymous 17.11.2014 / 19:53

1 answer

4

How are you trying to fetch? Here's a simple code for a COUNT (*) using MYSQLi.

$db = new mysqli('localhost', 'usuario', 'senha', 'easycontrol');

if ($db->connect_errno > 0){
    die('Impossível se conectar ao banco [' . $db->connect_error . ']');
}

$result = $db->query("select count(*) from ec_despesas");
$row = $result->fetch_row();
echo 'n: ', $row[0];
    
17.11.2014 / 20:10