次のようなPHPを含むページがあります。
<table>
<thead>
<tr>
<th class="wheniwant">Date</th>
<th class="wheniwant">Income Amount</th>
<th class="wheniwant">Expense Amount</th>
</tr>
</thead>
<?php
//DB CONNECTION
$varDatePaid = ""; $varIncomePaid =""; $varExpensePaid = "";
$sql = mysql_query(
"
SELECT DATE_FORMAT(`date_paid`, '%Y-%m') `date_paid`,
SUM(CASE WHEN `categoryType` = 'Income' THEN `amount_paid` END) `IncomeAmount`,
SUM(CASE WHEN `categoryType` = 'Expense' THEN `amount_paid` END) `ExpenseAmount`
FROM `accounting`
GROUP BY DATE_FORMAT(`date_paid`, '%Y-%m')
"
);
while($row = mysql_fetch_array($sql))
{
$varDatePaid = $row['date_paid'];
$varIncomePaid = $row['IncomeAmount'];
$varExpensePaid = $row['ExpenseAmount'];
?>
<tr>
<td><?php echo $varDatePaid; ?></td>
<td><?php echo $varIncomePaid; ?></td>
<td><?php echo $varExpensePaid; ?></td>
</tr>
<?php
}
?>
</table>
これは、次のようなテーブルを返します。
私は何かを追加したい:
$sql_query = "SELECT id, DATE_FORMAT(`date_paid`, '%Y') AS year FROM accounting GROUP BY year ORDER BY year DESC";
$result = mysql_query($sql_query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
echo '<option value='. $row['year'] . '>'. $row['year'] . '</option>';
結果を特定の年に限定するための何らかのフィルターを作成します。ページを離れずにこれを行うにはどうすればよいですか?