Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Working with the results in PHP

Exeu edited this page · 11 revisions

Show first 10 results

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.

<?php
//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('Small,Images,Offers')->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/>";
                }

                //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>";

}
Something went wrong with that request. Please try again.