I have a database of a restaurant and I want to generate the daily sales report of the products sold. So basically the columns are:
Product name | Qty | Amount
Now when I apply a while loop using php it shows me all the records available in database such as if I have Green Tea 15 times in a table it will display it 15 times with quantity 1.
I simply want to merge it and want to show quantity as 15.
My PHP code is:
<?php
$bt = $_POST['bt'];
$check_in = $_POST['check_in'];
if($bt != '') {
$g = mysql_query("select * from bill2 where date='{$check_in}'");
echo '
<div class="col-md-12">
<div class="box">
<div class="box-title">
</div>
<div class="box-body">
<table class="table table-bordered">
<tr>
<th>#</th>
<th>Item Name</th>
<th>Quantity Sold</th>
<th>Total Amount</th>
</tr>';
$x=0;
while($gff = mysql_fetch_assoc($g)) {
$x++;
echo '<tr>
<td>' . $x . '</td>
<td>' . $gff['itemid'] . '</td>
<td>' . $gff['qty'] . '</td>
<td>' . $gff['amount'] . '</td>
</tr>';
}
echo '</table></div></div></div>';
}
?>
output:
# Item Name Quantity Total Amount
1 Green Mint Tea 1 30
2 Green Mint Tea 1 30
3 Vanilla Tea 1 35
4 Black Tea 1 30
expected output:
# Item Name Quantity Total Amount
1 Green Mint Tea 2 60
2 Vanilla Tea 1 35
3 Black Tea 1 30