PHP
  Home arrow PHP arrow Page 7 - Using Amazon Web Services With PHP And SOAP (part 1)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 89
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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) - Turning The Pages
    ( Page 7 of 9 )

    You'll remember, from my explanation of the various arguments to BrowseNodeSearchRequest() a few pages back, that AWS returns search results in chunks of ten, and the "page" argument must be used to obtain subsequent pages of the result set.

    Thus far, all the examples you've seen have been limited to displaying ten items...not very useful in the real world at all. That's why this next example adds previous and next page links to assist in navigating between the different pages of the result set.



    <?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; // if no page specified, start with page 1 if (!$_GET['page']) { $page = 1; } else { $page = $_GET['page']; } // create a proxy so that WSDL methods can be accessed directly $proxy = $soapclient->getProxy(); // set up an array containing input parameters to be // passed to the remote procedure $params = array( 'browse_node' => 18, 'page' => $page, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'lite', 'devtag' => 'YOUR-TOKEN-HERE' ); // invoke the method $result = $proxy->BrowseNodeSearchRequest($params); $total = $result['TotalResults']; $items = $result['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> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <? // parse the $items[] array and extract the necessary information // (image, price, title, author, item URL) foreach ($items 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> <!-- next and prev page links --> <? $pageCount = ceil($total/10); ?> <table width="100%" cellspacing="0" cellpadding="5"> <tr> <td align="left"> <? if ($page != 1) { ?> <a href="<? echo $_SERVER['PHP_SELF']; ?>?page=<? echo $page-1; ?>">Previous page</a> <? } ?> &nbsp; </td> <td align="center">Page <? echo $page; ?> of <? echo $pageCount; ?></td> <td align="right"> &nbsp; <? if ($page < $pageCount) { ?> <a href="<? echo $_SERVER['PHP_SELF']; ?>?page=<? echo $page+1; ?>">Next page</a> <? } ?> </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>
    How does this work? It's actually pretty simple - first, the total number of items in the result set is obtained from the SOAP response and assigned to a variable; this number is then divided by ten and rounded up to obtain the total number of pages to be displayed. Then, previous and next page links are added to the bottom of the page - each link calls the same script again and passes it a new page number via the GET method. This page number is then incorporated into the call to BrowseNodeSearchRequest(), and a new data set is obtained and displayed.

    Here's what it looks like:



    One caveat, though: AWS 2.0 contains a bug that sometimes causes it to display an incorrect number of total results. Hopefully, this will be fixed in an upcoming release - until then, be warned.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





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