The source of the below data is a csv file that comes from a warehouse. System reads the csv file and saves in the table called warehouse_feedback. Warehouse splits the quantity and sends in multiple packages. That is the reason here I am having the same EANs multiple times. Here I am forced to save data in the same format as I received from Warehouse. Because I need to send this same data to other ERP system. Another thing is Same EAN will appear under different order ids.
I am able to display information up to some extent. Here is my code to get the below out put.
$stmt = $mysqliConn->prepare("SELECT id, hdr_id_fk, package_number, ean,
quantity, requested_qty, order_number
from warehouse_feedback
where hdr_id_fk =? ");
$hdr_id = 31;
$stmt->bind_param("i", $hdr_id);
$stmt->execute();
$result = $stmt->get_result();
$results = $result->fetch_all(MYSQLI_ASSOC);
$finalResults = [];
foreach($results as $result){
$finalResults[$result['ean']][] = $result;
}
<!-- table code -->
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Pack_num</th>
<th>Order Id</th>
<th>EAN</th>
<th>ReqQty</th>
<th>Confrmd Qty</th>
</tr>
</thead>
<tbody>
<?php foreach ($finalResults as $finalResult) {
$confirmedQuantity = 0
?>
<?php foreach ($finalResult as $finalRes) {
$confirmedQuantity += $finalRes['quantity'];
?>
<tr>
<td><?php echo $finalRes['id']; ?></td>
<td><?php echo $finalRes['package_number']; ?></td>
<td><?php echo $finalRes['order_number']; ?></td>
<td><?php echo $finalRes['ean']; ?></td>
<td><?php echo $finalRes['requested_qty']; ?></td>
<td><?php echo $finalRes['quantity']; ?></td>
</tr>
<?php } ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $finalResult[0]['ean']; ?></td>
<td><?php echo 'Req Qty -' . $finalResult[0]['requested_qty'] ?></td>
<td><?php echo 'Confirmed Qty -' . $confirmedQuantity; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Here some how my code is not considering Order_number Even the requested quantity is 7 If you see Under ID – 4 it is showing as 6 and same in Under ID – 8 , total requested quantity is 26, and it is showing as 18.
ID | Pack_num | Order Id | EAN | ReqQty | Confrmd Qty |
---|---|---|---|---|---|
1 | 1 | 3TAI91HB | 4046228076119 | 6 | 1 |
2 | 2 | 3TAI91HB | 4046228076119 | 6 | 3 |
3 | 3 | 3TAI91HB | 4046228076119 | 6 | 1 |
4 | 4 | 6GF4GWRT | 4046228076119 | 1 | 1 |
4046228076119 | Req Qty – 6 | Confrmd Qty – 6 | |||
5 | 5 | 31C3OD1H | 4046228076729 | 5 | 5 |
4046228076729 | Req Qty – 5 | Confrmd Qty – 5 | |||
6 | 23 | 1H32M34B | 4046228076123 | 18 | 12 |
7 | 24 | 1H32M34B | 4046228076123 | 18 | 3 |
8 | 25 | 1H32M34B | 4046228076456 | 8 | 5 |
4046228076456 | Req Qty – 18 | Confrmd Qty – 20 |
So I would like to have the below result.
Here count should be based on order_id
and ean
ID | Pack_num | Order Id | EAN | ReqQty | Confrmd Qty |
---|---|---|---|---|---|
1 | 1 | 3TAI91HB | 4046228076119 | 6 | 1 |
2 | 2 | 3TAI91HB | 4046228076119 | 6 | 3 |
3 | 3 | 3TAI91HB | 4046228076119 | 6 | 1 |
3TAI91HB | 4046228076119 | Req Qty – 6 | Confrmd Qty – 5 | ||
4 | 4 | 6GF4GWRT | 4046228076119 | 6 | 6 |
6GF4GWRT | 4046228076119 | Req Qty – 6 | Confrmd Qty – 6 | ||
5 | 5 | 31C3OD1H | 4046228076729 | 5 | 5 |
31C3OD1H | 4046228076729 | Req Qty – 5 | Confrmd Qty – 5 | ||
6 | 23 | 1H32M34B | 4046228076123 | 18 | 12 |
7 | 24 | 1H32M34B | 4046228076123 | 18 | 3 |
1H32M34B | 4046228076123 | Req Qty – 18 | Confrmd Qty – 15 | ||
8 | 25 | 1H32M34B | 4046228076456 | 8 | 5 |
1H32M34B | 4046228076456 | Req Qty – 8 | Confrmd Qty – 5 |
2
Answers
Here is the answer to my question.
I don't know everyone down voted. Does this have format issues or not clear or did I just asked I want this / that without showing any effort?
Any have THANKS
You have made life a little more difficult for yourself than it needs to be.
I have commented the code rather than writing a list of issues and changes