This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Working with the results in PHP
samedney edited this page Nov 28, 2010
·
11 revisions
This code will generate results from the class and loop through them, displaying each of the results in a new paragraph.
A list of the searchable Amazon categories are available here.
A list of all the Amazon response groups is available here.
//find what we are searching for using GET
$search = $_GET['search'];
//the category could also come from a GET if you wanted.
$category = "All";
define('AWS_API_KEY', 'ZZAAXXSSCCDDVVFFBBGGNHHMMJJ');
define('AWS_API_SECRET_KEY', 'aabbccddeeffgghhiijjkk');
define('AWS_ASSOCIATE_ID', 'abcdefg-21');
require 'lib/AmazonECS.class.php';
//declare the amazon ECS class
$amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'UK', AWS_ASSOCIATE_ID);
//tell the amazon class that we want an array, not an object
$amazonEcs->setReturnType(AmazonECS::RETURN_TYPE_ARRAY);
//create the amazon object (array)
$response = $amazonEcs->category($category)->responseGroup('Large')->search($search);
//check that there are items in the response
if (isset($response['Items']['Item']) ) {
//loop through each item
foreach ($response['Items']['Item'] as $result) {
//check that there is a ASIN code - for some reason, some items are not
//correctly listed. Im sure there is a reason for it, need to check.
if (isset($result['ASIN'])) {
//store the ASIN code in case we need it
$asin = $result['ASIN'];
//check that there is a URL. If not - no need to bother showing
//this one as we only want linkable items
if (isset($result['DetailPageURL'])) {
//set up a container for the details - this could be a DIV
echo "<p style='". IE_BACKGROUND . ";min-height: 60px; font-size: 90%;'>";
//create the URL link
echo "<a target='_Blank' href='" . $result['DetailPageURL'] ."'>";
//if there is a small image - show it
if (isset($result['SmallImage']['URL'] )) {
echo "<img class='shadow' style=' margin: 0px; margin-left: 10px; border: 1px solid black; max-height: 55px;' align='right' src='". $result['SmallImage']['URL'] ."'>";
}
// if there is a title - show it
if (isset($result['ItemAttributes']['Title'])) {
echo $result['ItemAttributes']['Title'] . "<br/>";
}
// put the brand name in - using small characters if it is present
if (isset($result['ItemAttributes']['Brand'])) {
echo "<small>";
echo $result['ItemAttributes']['Brand'] ;
echo "</small>";
}
//close the paragraph
echo "</p>";
}
}
}
} else {
//display that nothing was found - should no results be found
echo "<p style='". IE_BACKGROUND . "'>No Amazon suggestions found</p>";
}