我有一个包含一些 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>';
创建某种过滤器以将结果限制在特定年份。如何在不离开页面的情况下执行此操作?