php , SimpleXML, while loop

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-06-17T22:24:23Z Indexed on 2010/06/17 23:03 UTC
Read the original article Hit count: 354

Filed under:
|
|

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 .

© Stack Overflow or respective owner

Related posts about php

Related posts about simplexml