如何創建一個結果,無論PHP
或MySQL
這將顯示2005年,作爲例子,總結所有結果對於從日期straing PHP MySQL的每個新的一年
例輸入
-------------------------
Date \ Quantiti
-------------------------
12-05-2005 \ 5
-------------------------
23-08-2005 \ 8
-------------------------
11-02-2006 \ 4
-------------------------
26-09-2006 \ 2
-------------------------
實施例輸出中
---------------------------
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 {
}
?>
大字母的頭。你能否編輯你的問題並使其可讀? – cpap
你應該看看'YEAR()'和'SUM()':https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html – jeroen