0

I'm trying to get some information from ebay api and store it in database . I used simple xml to extract the information but I have a small issue as the information is not displayed for some items . if I make a print to the simple_xml I can see very well that the information is provided by ebay api . I have

$items = "220617293997,250645537939,230485306218,110537213815,180519294810";
$number_of_items  =  count(explode(",", $items));
$xml = $baseClass->getContent("http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=XML&appid=Morcovar-c74b-47c0-954f-463afb69a4b3&siteid=0&version=525&IncludeSelector=ItemSpecifics&ItemID=$items");
writeDoc($xml, "api.xml");
//echo $xml;
$getvalues = simplexml_load_file('api.xml');
//  print_r($getvalue);
$number = "0";

while($number < 6) {
    $item_number = $getvalues->Item[$number]->ItemID;
    $location = $getvalues->Item[$number]->Location;
    $title = $getvalues->Item[$number]->Title;
    $price = $getvalues->Item[$number]->ConvertedCurrentPrice;
    $manufacturer = $getvalues->Item[$number]->ItemSpecifics->NameValueList[3]->Value;
    $model = $getvalues->Item[$number]->ItemSpecifics->NameValueList[4]->Value;
    $mileage = $getvalues->Item[$number]->ItemSpecifics->NameValueList[5]->Value;

    echo "item number = $item_number <br>localtion = $location<br>".
         "title = $title<br>price = $price<br>manufacturer = $manufacturer".
         "<br>model = $model<br>mileage = $mileage<br>";
    $number++;

}

the above code returns

item number =
localtion =
title =
price =
manufacturer =
model =
mileage =
item number = 230485306218
localtion = Coventry, Warwickshire
title = 2001 LAND ROVER RANGE ROVER VOGUE AUTO GREEN
price = 3635.07
manufacturer = Land Rover
model = Range Rover
mileage = 76000
item number = 220617293997
localtion = Crawley, West Sussex
title = 2004 CITROEN C5 HDI LX RED
price = 3115.77
manufacturer = Citroen
model = C5
mileage = 76000
item number = 180519294810
localtion = London, London
title = 2000 VOLKSWAGEN POLO 1.4 SILVER 16V NEED GEAR BOX
price = 905.06
manufacturer = Right-hand drive
model =
mileage = Standard Car
item number =
localtion =
title =
price =
manufacturer =
model =
mileage = 

As you can see the information is not retrieved for a few items ... If I replace the $number manually like " $item_number = $getvalues->Item[4]->ItemID;" works well for any number .

2 Answers 2

1

I think your mistake is to initialize $number as a string. Replace $number = "0"; by $number = 0; to get the first entry working.

As for the last one - maybe there simply are just five entries in the XML result?

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much ! I have marked your answer as "accepted" . If you don't mind can you please let me know a "stable" solution to get the manufacturer , model and mileage ? The ebay API displays this information in the <ItemSpecifics> tree as name and value but sometimes the array number is different because some Items have more "specifics". Please see here an xml document example pastebin.com/NrvUdg8F and the print of the simple xml is pastebin.com/hY40YrWV
@Michael you'll probably have to walk through the specifics using foreach and look whether the property you're looking for is in there.
0

Try iterating through the list of items, instead of hard coding a limit into your while loop.

$items = "220617293997,250645537939,230485306218,110537213815,180519294810";
$xml = file_get_contents("http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=XML&appid=Morcovar-c74b-47c0-954f-463afb69a4b3&siteid=0&version=525&IncludeSelector=ItemSpecifics&ItemID=$items");
$sxml = simplexml_load_string($xml);


foreach ($sxml->Item as $item) {
  $out = array();
  $out[] = 'Item Number:'. $item->ItemID;
  $out[] = 'Location: '. $item->Location;
  $out[] = 'Title: '. $item->Title;
  $out[] = 'Price: '. $item->ConvertedCurrentPrice;
  $out[] = 'Manufacturer: '. $item->ItemSpecifics->NameValueList[3]->Value;
  $out[] = 'Model: '. $item->ItemSpecifics->NameValueList[4]->Value;
  $out[] = 'Mileage: '. $item->ItemSpecifics->NameValueList[5]->Value;

  echo implode('<br />', $out) . '<hr>';
}

Comments

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.