1

I read many useful answers here and the most of them helped me to create script for importing data from XML file. Problem is that this time i have additional part with images url's witch also needs to be updated into MySQL.
For now, i update MySQL with data from XML, after that use other script to download needed images. After website with XML feed changed they structure, i have problem to figure out how to update images url in array into MySQL row so i can download images after that. Even i choose to download images without updating into MySQL, i also can't download them.

This is XML structure

<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&amp;width=640&amp;group=1015&amp;module=1&amp;watermarktype=default&amp;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&amp;width=640&amp;group=1015&amp;module=1&amp;watermarktype=default&amp;position=Center</ImageURL>
      </Image>
    </Images>
  </UnitDTO>
</ArrayOfUnitDTO>

I am i am using this

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));

}

No metter what i tried, i can't import images url into imageurl MySQL row in array.

1 Answer 1

2

to get image url from above xml you have to run one more foreach loop, try something like below code and use it as per your requirement.

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;
        }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Ram, thank you for answer. Yes, i already run it but only 1st image is downloaded.There are some units with 5 and 6 images. That's main problem.
it's foreach loop you will get all the images just try it
I already tried before and tried once again. When i use echo, there are all images but when i update MySQL there are only one image. If i use INSERT instead REPLACE i am getting error Duplicate entry 'AP3147' for key 'PRIMARY'. So it try to use many times same entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.