My sql codes execute but I don't know how get the difference of purchase_request total_qty and purchase_order qty.
Table Purchase_Order
counter | qty |
---------------
100001 | 10 |
100001 | 10 |
100001 | 10 |
100004 | 30 |
Table Purchase_Request
counter | total_qty |
---------------------
100001 | 50 |
100002 | 100 |
100003 | 50 |
100004 | 70 |
I want to code just like this, but I don't know how to mix it in my codes.
a.total_qty-b.qty as balance
And this is my codes
<?php
$mysqli = new mysqli("localhost", "root", "", "test");
$result = $mysqli->query("
select a.counter,a.total_qty from purchase_request a inner join purchase_order b on a.counter= b.counter group by a.counter
");
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;" border="1px">
<thead>
<tr>
<th></th>
<th>counter</th>
<th>QTY</th>
<th>balance</th>
</tr>
</thead>';
echo'<tbody>';
$i=1;
while($row = $result->fetch_assoc()){
echo'<tr>
<td>'.$i++.'</td>
<td>'.$row['counter'].'</td>
<td>'.$row['total_qty'].'</td>
<td>'.$row['balance'].'</td>
</tr>';
}
echo "</tbody></table>";
?>