View code

Check another Amazon.com item

'."\n"; $Amazon=new Amazon(); $parameters=array( "region"=>"com", "AssociateTag"=>"jasonclarkinf-20", "Operation"=>"ItemSearch", // we will be searching "SearchIndex"=>"All", // search all categories, use "Books" to limit to books 'ResponseGroup'=>'Images,ItemAttributes,EditorialReview,Reviews,Similarities',// we want images, item info, reviews, and related items "Keywords"=>"$q"); // this is what we are looking for, you could use the book's title instead $queryUrl=$Amazon->getSignedUrl($parameters); //print out Query URL for dev purposes - TURN OFF in Production echo '

'.$queryUrl.'

'; $request=simplexml_load_file($queryUrl) or die ("xml response not loading"); if($request->Items->TotalResults > 0) { // we have at least one response //set Amazon xml values as specifc variables to be printed out below $image = $request->Items->Item->MediumImage->URL; if (empty($image)) { $image = '* Image Not Available'; } $title = $request->Items->Item->ItemAttributes->Title; $author = $request->Items->Item->ItemAttributes->Author; //simple logic check for author and director values, shows if (strlen($author) > 2) { $creator = $author; } elseif (empty($author)) { $creator = $request->Items->Item->ItemAttributes->Director; } else { $creator = '* Creator Not Available'; } $asin = $request->Items->Item->ASIN; $uri = $request->Items->Item->DetailPageURL; $editorialReview = $request->Items->Item->EditorialReviews->EditorialReview->Content; $CustomerReviews = $request->Items->Item->CustomerReviews->IFrameURL; //print out Amazon xml values as html echo ''."\n"; echo '

'.$title.'

'."\n"; echo '

'.$creator.'
ID (isbn or asin): '.$asin .'
Get full details

'."\n"; echo '

Customer Reviews

'."\n"; echo '

Editorial review: '.html_entity_decode($editorialReview).'

'."\n"; echo '

You might also like...

'."\n"; echo '
'."\n"; foreach ($request->Items->Item->SimilarProducts->SimilarProduct as $related) { echo '
'.html_entity_decode($related->Title).'
'."\n"; echo '
ID (isbn or asin): '.$related->ASIN.'
'."\n"; } echo '
'."\n"; //print out Amazon xml array for teaching purposes, next 3 lines should be removed in production environment echo "
";
var_dump($request);
echo "
"; } else { //no search results echo '

No results for your query for "'.$q.'"

'; } else: //show form and allow the user to check for Amazon.com reviews and more ?>