I am working on something to manage my finances with a Database and with PHP. From my homepage I want to select a month and make it execute a query so only the records in the database from this month are displayed.
Now I have this:
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']
);
}
Instead of making this code for every month, how can I make this more universal? I want to use the $monthselect
variable, but I have no idea where to start.