I am trying to output data for selected dates and think I have managed to do the sql query but it's currently not outputting the total amount, below is what it is currently outputting
I am looking for the following
From To Expense Category Expenses Total
01/01/2018 31/12/2018 Accounting Costs £0.00
01/01/2018 31/12/2018 Marketing £0.00
Below is the current code I have
<?php
if (isset($_POST['submit'])){
include('dbconnection.php');
$from=date('Y-m-d',strtotime($_POST['from']));
$to=date('Y-m-d',strtotime($_POST['to']));
$oquery=$mysqli->query("SELECT ec.expense_category_id, ec.expense_category_name,sum(e.expenseamount), date_format('$from','%d/%m/%Y') as `from`, date_format('$to','%d/%m/%Y') as `to` FROM expenses e join expense_category ec ON e.expense_category_id = ec.expense_category_id WHERE e.expddate between '$from' and '$to' group by ec.expense_category_name");
if ($oquery->num_rows > 0) {
while($orow = $oquery->fetch_array()){
?>
<tr>
<td><?php echo $orow['from'] ?></td>
<td><?php echo $orow['to'] ?></td>
<td><?php echo $orow['expense_category_name'] ?></td>
<td><?php echo "" . '£' . number_format($orow['expenseamount'], 2) . "";?></td>
</tr>
<?php
}
} else {
echo "0 Results";
}
}
?>
Can someone help please as I'm not 100% on PHP, I'm not sure if is to do with my sql query or is something else?