我试图从多个表中获取数据但我在第一个foreach语句中尝试获取的数据存在一些问题。
(我顺便使用medoo.in)。
$sales_order = $database->select("sales_order", "*", ["status" => "processing"]);
foreach($sales_order as $salesOrder) {
$entity_id = $salesOrder['entity_id'];
// Some other data from the sales_order table
$sales_order_item = $database->select("sales_order_item", "*", ["order_id" => $entity_id]);
foreach($sales_order_item as $salesOrderItem) {
// Other data from the sales_order_item table
$productID[] = $salesOrderItem['product_id'];
$sku[] = $salesOrderItem['sku'];
$qty[] = $salesOrderItem['qty_ordered'];
}
// Then dump the SKU to test data output
var_dump($sku);
}
正如您所看到的,$sales_order_item
需要在第一个foreach中,因为我需要$entity_id
,但这样做会导致我出现问题。它似乎重复了我的数据输出:
array(4) {
[0]=>
string(20) "FT0058P-White-Medium"
[1]=>
string(20) "FT0058P-White-Medium"
[2]=>
string(26) "FT0058P-Heather Grey-Large"
[3]=>
string(26) "FT0058P-Heather Grey-Large"
}
有没有更好的方法来做我想要实现的目标?