Hi I can't quite figure out what i'm doing wrong here, maybe an extra set of eyes can help me out, but I'm getting an error here, on the foreach statement:
$xmlstr2 = <<<XML
$match2[2]
XML;
$xml2 = simplexml_load_string($xmlstr2);
foreach ($xml2->Item as $node2) {
Here is the entire code...
And the error I get is Warning: Invalid argument supplied for foreach()
<?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$base = 'http://webservices.amazon.ca/onca/xml';
$query_string = '';
$params = array(
'Service' => 'AWSECommerceService',
'AssociateTag' => 'dillenger-20',
'SubscriptionId' => '06KH9GNG9M5G44EGJ702',
'ResponseGroup' => 'BrowseNodeInfo',
'Operation' => 'BrowseNodeLookup',
'BrowseNodeId' => '952768',
);
foreach ($params as $key => $value) {
$query_string .= "$key=" . urlencode($value) . "&";
}
$url = "$base?$query_string";
$xml = file_get_contents($url);
$matched = preg_match('/(.*?)<\/Request>(.*?)<\/BrowseNodes><\/BrowseNodeLookupResponse>/is', $xml, $match);
$xmlstr = <<<XML
$match[2]
XML;
$xml = simplexml_load_string($xmlstr);
foreach ($xml->Children->BrowseNode as $node) {
$id = $node->BrowseNodeId;
$name = $node->Name;
$color = $colornumber % 2;
echo "<li class=\"listitem$color\"><a href=\"?var1=$id\">$name</a></li>\n";
$colornumber = $colornumber + 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
</ul>
</div>
<div id="content">
<?
if (isset($_GET[var1])) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$base = 'http://webservices.amazon.ca/onca/xml';
$query_string = '';
$params = array(
'Service' => 'AWSECommerceService',
'AssociateTag' => 'dillenger-20',
'SubscriptionId' => '06KH9GNG9M5G44EGJ702',
'ResponseGroup' => 'Medium',
'SearchIndex' => 'DVD',
'Sort' => 'titlerank',
'Condition' => 'All',
'Operation' => 'ItemSearch',
'BrowseNode' => $_GET[var1]
);
foreach ($params as $key => $value) {
$query_string .= "$key=" . urlencode($value) . "&";
}
$url2 = "$base?$query_string";
$xml2 = file_get_contents($url2);
$matched2 = preg_match('/(.*?)<\/Request>(.*?)<\/Items><\/ItemSearchResponse> <br \/>/is', $xml2, $match2);
$xmlstr2 = <<<XML
$match2[2]
XML;
$xml2 = simplexml_load_string($xmlstr2);
foreach ($xml2->Item as $node2) {
/*$ASIN = $node2->ASIN;
$ListPrice = $node2->ListPrice->FormattedPrice;
$Title = $node2->Title;
$OurPrice = $node2->LowestNewPrice->FormattedPrice;
$ImageURL = $node2->SmallImage->URL;
$color = $colornumber % 2;
echo "\n<div class=\"item$color\">\n<a href=\"?var2=$ASIN\"><img src=\"$ImageURL\" border=\"0\" alt=\"$Title\" class=\"image1\"></a>\n<a href=\"?var2=$ASIN\" class=\"productname1\">$Title</a>\nList Price:<span class=\"listprice1\">$ListPrice</span><br>\nOur Price:<span class=\"ourprice1\">$OurPrice</span>\n</div>\n";
$colornumber = $colornumber + 1;*/
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
?>