Ich mache eine Bill Of Materials Tabelle. Meine XML übergeordneten Knoten ist das Produkt, das wir machen, und die Kinder werden die BOM Linien beispielsErstellen Sie mehrere Zeilen in mysql mit Eltern und Schleife von Kindern XML mit PHP
<BOM>
<ProductName>This</ProductName>
<BOMLines>
<BOMLine>
<ProductCode>Widget-1</ProductCode>
<Qty>111</Qty>
</BOMLine>
<BOMLine>
<ProductCode>Widget-2</ProductCode>
<Qty>222</Qty>
</BOMLine>
<BOMLine>
<ProductCode>Widget-3</ProductCode>
<Qty>333</Qty>
</BOMLine>
</BomLines>
</BOM>
Mein Endziel, PHP für Zeile ein einzelnes einzufügen jedes BOMLine Produktcode zusammen mit dem übergeordneten Produktinformationen als solche;
TABLE bom
id productCode lineCode qty
1 PROD-1 Widget-1 111
2 PROD-1 Widget-2 222
3 PROD-1 Widget-3 333
Dies ist der Code, den ich bisher habe, aber ich kann nicht die Elterninformationen auf diese Weise arbeiten;
function updateBOM() {
$BOMXml = getBOMs('');
foreach ($BOMXml->BOM->BOMLines->BOMLine as $BOM) {
$BOMLine = $BOM->ProductCode;
$BOMQty = $BOM->Qty;
$ParentProduct = $BOMXML->BOM->ProductName
$sql = "INSERT INTO bom (productCode, lineCode, Qty) VALUES ('$ParentProduct', '$BOMLine', '$BOMQty')";
$retval = mysql_query($sql);
if(! $retval) {
die('Could not enter data: ' . mysql_error());
}
$count += '1';
}
Abfrage ausgeführt wird, erhalte ich einige Daten, aber alle Eltern Produkt ist in jeder Zeile leer ist: z