[英]Updating MySQL from XML file using PHP
我在這里閱讀了許多有用的答案,其中大多數幫助我創建了用於從XML文件導入數據的腳本。 問題是,這次我還有圖像URL的女巫的其他部分,也需要更新到MySQL中。
現在,我使用來自XML的數據更新MySQL,然后使用其他腳本下載所需的圖像。 在使用XML feed的網站更改了它們的結構之后,我很難弄清楚如何將數組中的圖像url更新到MySQL行中,以便之后可以下載圖像。 即使我選擇下載圖像而不更新到MySQL,我也無法下載它們。
這是XML結構
<ArrayOfUnitDTO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UnitDTO>
<Category>Category name</Category>
<code>863</code>
<Status>Blocked</Status>
<RefNo>12345</RefNo>
<Images>
<Image>
<Title>Community</Title>
<ImageURL>http://imageaddress.com/images/watermark.aspx?imageurl=/uf/1015/GroupUpdate/unit/350/350_Image.jpg&width=640&group=1015&module=1&watermarktype=default&position=Center</ImageURL>
</Image>
<Image>
<Title>Local Area Image</Title>
<ImageURL>http://imageaddress.com/images/watermark.aspx?imageurl=/uf/1015/GroupUpdate/unit/631/631_Image.jpg&width=640&group=1015&module=1&watermarktype=default&position=Center</ImageURL>
</Image>
</Images>
</UnitDTO>
</ArrayOfUnitDTO>
我在用這個
foreach ($listings ->UnitDTO as $listingInfo) //loop read xml
{
$RefNo = $listingInfo->RefNo;
$Category = $listingInfo->Category;
$code = $listingInfo->code;
$Status = $listingInfo->Status;
mysqli_query($link,"REPLACE INTO UnitDTO (`RefNo`, `Category`, `code`, `Status`) VALUES ('$RefNo', '$Category', '$code', '$Status',)") or die(mysqli_error($link));
}
我嘗試過的方法不行,我無法將圖像URL導入imageurl
MySQL數組中。
要從xml上方獲取圖像url,您必須再運行一個foreach循環,嘗試以下代碼,並根據需要使用它。
foreach ($listings ->UnitDTO as $listingInfo){
$RefNo = $listingInfo->RefNo;
$Category = $listingInfo->Category;
$code = $listingInfo->code;
$Status = $listingInfo->Status;
foreach ($listingInfo->Images->Image as $image){
echo $image->ImageURL;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.