How can I create a result, in either PHP
or MySQL
which will show the year 2005, as example, and sum all results
Example input
-------------------------
Date \ Quantiti
-------------------------
12-05-2005 \ 5
-------------------------
23-08-2005 \ 8
-------------------------
11-02-2006 \ 4
-------------------------
26-09-2006 \ 2
-------------------------
Example ouput
---------------------------
year \ Total
---------------------------
2005 \ 13
---------------------------
2006 \ 6
---------------------------
<?php
$sql = "SELECT * FROM mytable ORDER BY date DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$date = $row["date"];
$quantiti = $row["quantiti"];
// here i need code for each new year
}
} else {
}
?>