PHP
  Home arrow PHP arrow Page 3 - Using Amazon Web Services With PHP And...
Dev Shed Forums 
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 
Moblin 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      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 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

    - 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
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP





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