Display data from a table by adding a specific column

0

Good afternoon!

I'm a beginner in php and I'm trying to build a table that tells you the date and sum of sales, but I can only display the sum of the values but I can not present the date ... p>

$mysqli = new MySQLi( 'localhost', 'login', 'senha', 'db' );
$q_soma= ('SELECT SUM(valor) AS resultado FROM vendas GROUP BY data');

if ($result = $mysqli->query($q_soma)) {
    while ($row = $result->fetch_assoc()) {
        printf ("%s <br />", $row["resultado"]);
    }
    $result->close();
};
    
asked by anonymous 24.03.2017 / 19:42

1 answer

0
  

$ q_soma = ('SELECT SUM (value) AS result FROM sales GROUP BY data');

Switch to:

  

$ q_soma = ('SELECT SUM (value) AS result, data FROM GROUP BY data');

With all the changes made, it looks something like this:

$mysqli = new MySQLi( 'localhost', 'login', 'senha', 'db' );
$q_soma= ('SELECT SUM(valor) AS resultado FROM vendas GROUP BY data');

if ($result = $mysqli->query($q_soma)) {
    while ($row = $result->fetch_assoc()) {
        print "vendas: {$row['resultado']} - {$row['data']}";
    }
    $result->close();
};
    
24.03.2017 / 20:14