データベースと 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
、どこから始めればよいかわかりません。