Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Working with the results in PHP

samedney edited this page Nov 27, 2010 · 11 revisions

Loop through results. Displaying item title, brand and image as a link.

$search =$itemName;
$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 amazong 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>";

}
Clone this wiki locally