PHP
  Home arrow PHP arrow Page 3 - Using Amazon Web Services With PHP And SOAP (part 2)
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 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 21
    2002-11-13


    Table of Contents:
  • Using Amazon Web Services With PHP And SOAP (part 2)
  • Rolling The Stones
  • Searching For Words
  • Drilling Deeper
  • Riding The Popularity Metrics
  • Bagging It
  • Linking Out

  • 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 2) - Searching For Words
    ( Page 3 of 7 )

    You might remember this page from the first part of this article:



    You might also remember that I never got around to adding a search box. Let's do that now:

    <?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); // create a proxy so that WSDL methods can be accessed directly $proxy = $soapclient->getProxy(); // if no page specified, start with page 1 if (!$_GET['page']) { $page = 1; } else { $page = $_GET['page']; } // if keyword available, use it if ($_POST['keyword'] && $_POST['keyword'] != "") { $keyword = $_POST['keyword']; } if ($_GET['keyword'] && $_GET['keyword'] != "") { $keyword = $_GET['keyword']; } // if a keyword is present, do a keyword search if ($keyword) { $params = array( 'keyword' => htmlentities($keyword), 'page' => $page, 'mode' => 'books', 'tag' => 'melonfire-20', 'sort' => '+pmrank', 'type' => 'lite', 'devtag' => 'YOUR-TOKEN-HERE' ); // invoke the method $result = $proxy->KeywordSearchRequest($params); } else { // else perform a node browse $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> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td>Browse the catalog below, or search for a specific title &nbsp;</td> <td><br><form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"><input type="text" name="keyword"></form></td> </tr> </table> <p> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <? 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; ?>&keyword=<? echo $keyword; ?>">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; ?>&keyword=<? echo $keyword; ?>">Next page</a> <? } ?> </td> </tr> </table> </body> </html>
    As you can see, this is pretty simple - I've added a small input box for the user to enter a search term, and modified the form processor to check for a keyword and run a KeywordSearchRequest() if it's present, or a BrowseNodeSearchRequest() for the default node if it isn't. The next and previous page links also now pass an additional "keyword" parameter back and forth, so that the user can page through either the product catalog returned by BrowseNodeSearchRequest() or the result set returned by KeywordSearchRequest().

    Here are a couple of screenshots demonstrating what the final result looks like:



     
     
    >>> 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 2 hosted by Hostway
    Stay green...Green IT