Forum Moderators: open
What I need to do is to get some information of every item for my website coming from stores like price, release date, list price and store them into my db. So basically I need to parse the XML feed and get variables in PHP so I can play with them. I don't know and I'm sure it can be done because a lot of sites do it.
Anyway is there anyone who uses Amazon? I tried to analyze the full item feed but I couldn't find where are the list price, release date, date added.
Thank you.
amazon's limit can also be worked around by putting multiple operations into one request. the php max execution time might be harder to work with. parsing xml ist quite time consuming, so you might have to get used to retrieving few items if your host has a very restrictive setting.
what exactly do you want to do?
also, if you know the ItemIDs, you can request multiple items in one request, so a while-loop for 100 items wouldn't result in 100 requests, but in 10 or less. check the docs for multiple operations.
there's no identification for each item (only array 0,1,2 and so on) so I can't find a way to store the price to a relative proper ItemID into the database.
I could to a loop into a loop but if the items are more than 100 I should find a way to divide them into parts. I should work on that, any advice?
[edited by: Sandro87 at 1:29 pm (utc) on June 3, 2009]
$asinprice = array();
foreach($myArray['Items'] AS $item)
{
$asinprice[ $item['ASIN'][0]['Value'] ] = $item['Price'][0]['Value'];
}
No, because the xml structure of amazon puts the ASIN into a single tag so the array is like:
$item[0][value]
$item[1][value].
The ASIN tag is put into "item" in first line and then closed right away, it doesn't include all the info, the item tag does.
item
array 0
asin /asin
price /price
/item
item
array 1
asin /asin
price /price
/item
it should be like this to make it to work like your example that's why I'm kind of confused how to do it.
item
asin
price /price
/asin
/item
It turns an XML string into a PHP object that can be traversed using simple loops and object syntax. It also has a fairly reliable XPATH method.
Working with SimpleXML isn't as "simple" as you'd hope, and it may take some work to get the hang of it. But once you "get" it, it's a nice tool to have in your XML/PHP arsenal.
[edited by: Sandro87 at 2:41 pm (utc) on June 6, 2009]
// xml source
$xml_file = "am_titlesEUR.xml";
//id examples , they'd come from a databse query
$ids = array("031398109389","097361427843","786936787665","883929039616","883929034178","031398240785");
$xml = new SimpleXmlElement(file_get_contents($xml_file));
foreach($xml->result->row as $row){
// here I need to make: if this row is = to ONE of ANY values of the $ids arrya then do the function.
if ($row->ID == $ids[]){
echo $row->Title ." ¦ <b>". $row->Price ."</b><br/>";
}
}
Is there a php function for that?