Be grateful for some help on this. I have a very long xml form with over 80 items to insert into my db.
I've researched this and for some reason my foreach loop doesn't work.
I've reduced the insert here to give an idea of what I am trying to do.
I can insert the first 'property / item into the database so I know I have no issues with the inserts etc.
For some reason the loop won't show the other 79 items in the db.
$affectedRow = 0;
$xml = simplexml_load_file('properties2.xml') or die("can not find it");
foreach($xml->children() as $row) {
$reference = $row->branch->properties->property['reference'];
$instructedDate = $row->branch->properties->property->instructedDate;
$price_text = $row->branch->properties->property->price_text;
$sql = "INSERT INTO test( reference, instructedDate, price_text) VALUES ('". $reference ."','". $instructedDate ."','". $price_text ."')";
$result = mysqli_query($conn, $sql);
if (! empty($result )) {
$affectedRow ++;
} else {
$error_message = mysqli_error($conn) . "\n";
}
}
?>
eg xml file
-<agency branchName="billies Estate Agents " name="billie ea" xsi:noNamespaceSchemaLocation="http://www.feedcompany.co.uk/xmlexport/feedcompanyXMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<branches>
-<branch name="billies Estate Agents ">
-<properties>
-<property reference="00000477">
<instructedDate>26/02/2018 15:11:56</instructedDate>
<price_text>Offers in Excess of £200,000</price_text>
</property
-<property reference="00000478">
<instructedDate>26/02/2018 15:11:56</instructedDate>
<price_text>Offers in Excess of £200,000</price_text>
</property>