我有这个xml Feed ...
$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);
}
......这部分剧本......
{{1}}
...结果是:导入了标题,描述和价格,但无法导入image1和images2。 为什么?我是初学者。拜托,有人可以帮帮我吗?
答案 0 :(得分:1)
这两张照片不是产品的子女,而是其孙子。只需将父images->
添加到路径中即可获取其值:
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);
}