我正在使用数据库和 PHP 来管理我的财务。在我的主页上,我想选择一个月份并使其执行查询,以便仅显示该月数据库中的记录。
现在我有这个:
if (isset($_GET['january2013']))
{
//Select the incomes
try
{
$sql = 'SELECT id, type, date, amount, description, category FROM `transactions`
WHERE type = "income"
AND month(date) = ' . $monthselect . '
ORDER BY `transactions`.`id` DESC
LIMIT 0,50';
$result2 = $pdo->query($sql);
}
//Error handling.
catch (PDOException $e)
{
$output3 = 'Error fetching records: ' . $e->getMessage();
include '/errors/output.html.php';
exit();
}
//Display the records.
foreach ($result2 as $row)
{
$incomesJan2013[] = array(
'id' => $row['id'],
'type' => $row['type'],
'date' => $row['date'],
'amount' => $row['amount'],
'description' => $row['description'],
'category' => $row['category']
);
}
我怎样才能使它更通用,而不是每个月都制作这个代码?我想使用这个$monthselect
变量,但我不知道从哪里开始。