Reputation: 3
I have this xml feed ...
<products>
<product>
<title>Mini Piscina</title>
<description>Mini piscina penru copii pana la 6 ani.</description>
<price>22.00</price>
<images>
<image1>produs_1402038969.jpg</image1>
<image2>produs_1402382460.jpg</image2>
</images>
</product>
</products>
... and this part of script ...
$xml=simplexml_load_file("../feed/feed") or die("Error: Cannot create object");
$partener = 'toys';
foreach($xml -> product as $row) {
$magazin = $partener;
$titlu = $row -> title;
$descriere = $row -> description;
$pret = $row -> price;
$imagine1 = $row -> images1;
$imagine2 = $row -> images2;
$sql = "INSERT INTO toys (magazin,titlu,descriere,pret,imagine1,imagine2)
VALUES ('$magazin','$titlu','$descriere','$pret','$imagine1','$imagine2') ";
mysqli_query($conn, $sql);
}
... the result is: title, descrition and price are imported but image1 and images2 can not be imported. Why? I'm a beginner. Please, can anybody help me?
Upvotes: 0
Views: 135
Reputation: 107687
The two images are not the children of product but its grandchildren. Simply, add the parent images->
to the path to obtain their values:
foreach($xml -> product as $row) {
$magazin = $partener;
$titlu = $row -> title;
$descriere = $row -> description;
$pret = $row -> price;
$imagine1 = $row->images->image1;
$imagine2 = $row->images->image2;
$sql = "INSERT INTO toys (magazin,titlu,descriere,pret,imagine1,imagine2)
VALUES ('$magazin','$titlu','$descriere','$pret','$imagine1','$imagine2') ";
mysqli_query($conn, $sql);
}
Upvotes: 1