私のforeachループが生成されたProductionOrderIDの5つすべてに対してループすることができる理由を特定できないようですが、最初のIDのデータを返します。php foreachループは配列内の最初の反復の値を返すだけです
それは、配列が正しくループしていることをあなたがここに現在の結果を見ることができるように私の理解です:https://i.imgur.com/JWD3nis.pngが、どのような奇妙なのはIDです:あたりなど、すべてが空白、2が生成されている何のテーブルを持っていないし、ID 5が作成した2つのテーブルを持っていますimgurのスクリーンショットがリンクされました。
私はサンプルデータを2倍にしましたが、重複や問題が見つからないテーブルごとに5つのユニークなレコードがあります。
EDIT:1 どのようにループ機能を働かせたいかを明確にするために、欲しい結果を述べることを忘れました。このスクリーンショットを参照してください:https://i.imgur.com/4h7l49p.png(乾杯)。
EDIT:2 ここでは、SQLのエクスポートです:https://i.imgur.com/idVR5ev.png
EDIT:3 新しい、更新されたコード(おかげで砂)https://pastebin.com/MG2gtASu そして、ここには私のERDそれが役立つはずです:
<?php
include('OrderCore/connect-db.php');
$POIds = array();
if ($result = $mysqli->query("SELECT ProductionOrderID FROM ProductionOrder")) {
while ($row = $result->fetch_object()) {
$POIds[] = $row->ProductionOrderID;
}
}
foreach ($POIds as $index => $OrderId) {
if ($result = $mysqli->query("
SELECT *
FROM ProductionOrder AS p
LEFT JOIN ProductionOrderStatus AS s ON (p.ProductionOrderID = s.ProductionOrderStatusID)
LEFT JOIN NotGood AS n ON (p.ProductionOrderID = n.NGID)
LEFT JOIN BatchOrder AS b ON (p.ProductionOrderID = b.BatchID)
LEFT JOIN Brand AS bd ON (p.ProductionOrderID = bd.BrandID)
LEFT JOIN CustomerOrder AS co ON (p.ProductionOrderID = co.COID)
LEFT JOIN Customer AS c ON (p.ProductionOrderID = c.CustomerID)
LEFT JOIN CustomerOrderStatus AS cos ON (p.ProductionOrderID = cos.COStatusID)
WHERE p.ProductionOrderID='$OrderId'")) {
while($row = $result->fetch_object()) {
print "<h1>Order: $OrderId</h1>";
print "<table class='table table-striped'>";
print "<tr> <th>PO ID</th> <th>PO #</th> <th>Order Quantity</th> <th>Balance Left</th> <th>Production Date</th> <th>Production Order Status</th> <th>Not Good ID</th> </tr>";
print "<td>" . $row->ProductionOrderID . "</td>";
print "<td>" . $row->PONum . "</td>";
print "<td>" . $row->OrderQTY . "</td>";
print "<td>" . $row->BalLeftNum . "</td>";
print "<td>" . $row->ProductionDate . "</td>";
print "<td>" . $row->ProductionOrderStatusID . "</td>";
print "<td>" . $row->NGID . "</td>";
print "</tr>";
print "</table>";
//BatchOrder
print "<table class='table table-striped'>";
print "<tr> <th>Batch ID</th> <th>Brand Name</th> <th>Batch Quantity</th> <th>Availability Date</th> <th>Remaining Balance</th> <th>Production Order ID</th> </tr>";
print "<td>" . $row->BatchID . "</td>";
print "<td>" . $row->BrandID . "</td>";
print "<td>" . $row->BatchQTY . "</td>";
print "<td>" . $row->AvailDate . "</td>";
print "<td>" . $row->RemainBal . "</td>";
print "<td>" . $row->ProductionOrderID . "</td>";
print "</tr>";
print "</table>";
//CustomerOrder
print "<table class='table table-striped'>";
print "<tr> <th>Customer ID</th> <th>Customer Name</th> <th>Invoice Quantity</th> <th>Invoice #</th> <th>Shipping Date</th> <th>Batch ID</th> <th>CO Status</th> </tr>";
print "<td>" . $row->COID . "</td>";
print "<td>" . $row->CustomerID . "</td>";
print "<td>" . $row->InvoiceQTY . "</td>";
print "<td>" . $row->InvoiceNum . "</td>";
print "<td>" . $row->ShipDate . "</td>";
print "<td>" . $row->BatchID . "</td>";
print "<td>" . $row->COStatusID . "</td>";
print "</tr>";
print "</table>";
}
}
else
{
print "No results to display!";
}
}
$mysqli->close();
?>
「SQL」が実行されるたびに1ページまたは5レコードをループしますか?テーブルにレコードを表示したいだけですか? – Sand
私はすべてのレコード(ProductionOrder)をループしたいです。現在は5ですが、5または500になる可能性があります。 –
「$ POIds」はあなたに私に言うことができますか? – Sand