PHP
  Home arrow PHP arrow Page 6 - Using Amazon Web Services With PHP And...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using Amazon Web Services With PHP And SOAP (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 87
    2002-11-06

    Table of Contents:
  • Using Amazon Web Services With PHP And SOAP (part 1)
  • Remote Control
  • The Bare Necessities
  • Anatomy Class
  • The Bookworm Turns
  • Sorting Things Out
  • Turning The Pages
  • Weapon Of Choice
  • Hooking Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Amazon Web Services With PHP And SOAP (part 1) - Sorting Things Out


    (Page 6 of 9 )

    Now, the list displayed on the previous page is sorted in the default order imposed by Amazon.com. However, AWS allow you to alter this sort order by specifying an optional "sort" argument in the call to BrowseNodeSearchRequest(). This "sort" argument allows you to sort products by price, by sales rank, by rating, by date or alphabetically.

    In order to demonstrate this, consider the following enhancement to the example on the previous page, which performs three BrowseNodeSearchRequest() calls, each one applying a different sort criteria. The first one displays items in the default order; the second displays featured items first; and the third displays items by sales rank. Notice how the results of these three AWS calls can be massaged to create a more dynamic, informative and user-friendly page.

    <?php // include class include("nusoap.php"); // create a instance of the SOAP client object $soapclient = new soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl", true); // uncomment the next line to see debug messages // $soapclient->debug_flag = 1; // create a proxy so that WSDL methods can be accessed directly $proxy = $soapclient->getProxy(); // get items from the catalog // sort order is default $catalogParams = array( 'browse_node' => 18, 'page' => 1, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'lite', 'devtag' => 'YOUR-TOKEN-HERE' ); $catalogResult = $proxy->BrowseNodeSearchRequest($catalogParams); $catalogTotal = $catalogResult['TotalResults']; $catalogItems = $catalogResult['Details']; // get today's featured items // sort order is by featured items $featuredParams = array( 'browse_node' => 18, 'page' => 1, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'lite', 'sort' => '+pmrank', 'devtag' => 'YOUR-TOKEN-HERE' ); $featuredResult = $proxy->BrowseNodeSearchRequest($featuredParams); $featuredTotal = $featuredResult['TotalResults']; $featuredItems = $featuredResult['Details']; // get bestsellers // sort order is by sales ranking $bestsellersParams = array( 'browse_node' => 18, 'page' => 1, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'lite', 'sort' => '+salesrank', 'devtag' => 'YOUR-TOKEN-HERE' ); $bestsellersResult = $proxy->BrowseNodeSearchRequest($bestsellersParams); $bestsellersTotal = $bestsellersResult['TotalResults']; $bestsellersItems = $bestsellersResult['Details']; // format and display the results ?> <html> <head> <basefont face="Verdana"> </head> <body bgcolor="white"> <p>&nbsp;<p> <table width="100%" cellspacing="0" cellpadding="5"> <tr> <td bgcolor="Navy"><font color="white" size="-1"><b>Welcome to The Mystery Bookstore!</b></font></td> <td bgcolor="Navy" align="right"><font color="white" size="-1"><b><? echo date("d M Y", mktime());?></b></font></td> </tr> </table> <p> Browse the catalog below, or search for a specific title. <p> <!-- outer table --> <table width="100%" cellspacing="0" cellpadding="5"> <tr> <td align="left" valign="top" rowspan="2" width="65%"> <!-- inner catalog table --> <table border="0" cellspacing="5" cellpadding="0"> <? // parse the $items[] array and extract the necessary information // (image, price, title, author, item URL) foreach ($catalogItems as $i) { ?> <tr> <td align="center" valign="top" rowspan="3"><a href="<? echo $i['Url']; ?>"><img border="0" src=<? echo $i['ImageUrlSmall']; ?>></a></td> <td><font size="-1"><b><? echo $i['ProductName']; ?></b> / <? echo implode(", ", $i['Authors']); ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">List Price: <? echo $i['ListPrice']; ?> / Amazon.com Price: <? echo $i['OurPrice']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1"><a href="<? echo $i['Url']; ?>">Read more about this title on Amazon.com</a></font></td> </tr> <tr> <td colspan=2>&nbsp;</td> </tr> <? } ?> </table> </td> <td valign="top"> <font size="-1"> <!-- featured item table --> <table border="1" cellspacing="0" cellpadding="5"> <tr> <td> <b><font size="-1">Today's Featured Items:</font></b> <ul> <? for ($x=0; $x<5; $x++) { $f = $featuredItems[$x]; ?> <li><i><a href="<? echo $f['Url']; ?>"><font size="-1"><b><? echo $f['ProductName']; ?></b> - <? echo implode(", ", $f['Authors']); ?> (<? echo $f['OurPrice']; ?>)</font></a></i> <p> <? } ?> </ul> </td> </tr> </table> <p> <!-- bestseller list --> <table border="1" cellspacing="0" cellpadding="5"> <tr> <td> <b><font size="-1">Bestsellers:</font></b> <ul> <? for ($y=0; $y<5; $y++) { $b = $bestsellersItems[$y]; ?> <li><i><a href="<? echo $b['Url']; ?>"><font size="-1"><b><? echo $b['ProductName']; ?></b> - <? echo implode(", ", $b['Authors']); ?> (<? echo $b['OurPrice']; ?>)</font></a></i> <p> <? } ?> </ul> </td> </tr> </table> </font> </td> </tr> </table> <font size="-1"> Disclaimer: All product data on this page belongs to Amazon.com. No guarantees are made as to accuracy of prices and information. YMMV! </font> </body> </html>
    In this case, the additional "sort" argument is used to obtain a list of featured items and bestsellers within the Mystery node of the Amazon book database. Here's what the output looks like:



    A number of other sort criteria are available in AWS - take a look at the documentation for details.

    More PHP Articles
    More By icarus, (c) Melonfire


       · Hi,Could you please guide me how to create an user defined data types in the php...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT