我似乎无法确定为什么我的foreach循环能够循环创建所有5个ProductionOrderID,但只返回第一个ID的数据。php foreach循环只返回数组中第一次迭代的值
这是我的理解是,阵列正确循环,你可以看到当前结果这里:https://i.imgur.com/JWD3nis.png但有什么奇怪的是ID:2有没有表生成和ID 5具有创建2个表,所有空白按刚刚链接的imgur截图。
我检查了一下我的样本数据,每张表有5个独特的记录,没有重复或我能找到的问题。
编辑:1 我忘了提到希望的结果,以澄清我希望循环工作。请看这个屏幕截图:https://i.imgur.com/4h7l49p.png(干杯沙)。
编辑:2 下面是SQL的一个出口:https://pastebin.com/MG2gtASu 这里是我的ERD它应该帮助:https://i.imgur.com/idVR5ev.png
编辑:3 新的,更新的代码(感谢沙) :
<?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();
?>
你想循环5每页或5记录每次'SQL'运行?或者你只是想在你的表中显示记录? – Sand
我想循环每条记录(ProductionOrder);这是目前的5,但可能是5或500. –
好,你能告诉我,'$ POIds'做什么? – Sand