I looked over PHPDelusions website few times before asking this, as well as used Google but I still can't seem to get the code to work, or find a solution that remotely mirrors my question in general.
I made a super simple PHP7 script for managing Receipts. The fields are simple.
id (int 12), amount (varchar 8), category (int 2), date (date)
The problem I'm facing is I'm trying to Count the Total Amount of money based on Categories. So let's say Category = 1 would count all Amounts with that respective category and so on.
Here is my existing code.
function getAmountCount(PDO $pdo, $cat) {
$data = $pdo->prepare("SELECT COUNT(*) FROM `receipts` WHERE category = :cat_id");
$data->bindValue(':cat_id', $cat, PDO::PARAM_INT);
$data->execute();
$result = $data->fetchColumn();
echo money_format('%(#10n', $result['amount']).' CAD';
}
#and here is how we call it in the script
echo getAmountCount($pdo, 1);
The current code returns: $ 0.00 CAD