
April 6th, 2003, 01:43 PM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Here's the code:
PHP Code:
<html>
<head>
<basefont face="Verdana" size="2">
</head>
<body bgcolor="#F0F0F0">
<table width="100%" cellspacing="1" cellpadding="5">
<tr>
<td bgcolor="Navy"><font color="white" size="-1"><b>Hunting at Amazon</b></font></td>
</tr>
</table>
<?
if (!$_POST['query'])
{
?>
Select a category:
<form method="post" action="wsDemo.php">
<select name="type" size="5">
<option value="author">Author</option>
<option value="artist">Artist</option>
<option value="actor">Actor</option>
<option selected value="director">Director</option>
<option value="manufacturer">Manufacturer</option>
</select>
<BR><BR> Enter a search term:<BR><input type="text" name="query">
<BR><BR><input type="Submit">
</form>
<?
}
else
{
$ServiceType = $_POST['type'];
// include class
include("nusoap.php");
// create a instance of the SOAP client object
$soapclient = new soapclient(" [url]http://soap.amazon.com/schemas2/AmazonWebServices.wsdl[/url] ", true);
// Create a proxy so that WSDL methods can be accessed directly. We can now invoke the remote method as method of the proxy class, and pass our parameters directly. The proxy objects will handle the details such as matching up parameters values to their names, assigning namespaces and types.
$proxy = $soapclient->getProxy();
// at this point you can use the following commented lines of code as check for error.
if ($err = $proxy->getError()) {
print "ERROR: $err";
}
// set up an array containing input parameters to be
// passed to the remote procedure
// use a switch loop to define the search parameters for each type
switch ($ServiceType)
{
case "author":
$mode = "books";
$MyFunc = "AuthorSearchRequest";
break;
case "artist":
$mode = "music";
$MyFunc = "ArtistSearchRequest";
break;
case "actor":
$mode = "vhs";
$MyFunc = "ActorSearchRequest";
break;
case "director":
$mode = "vhs";
$MyFunc = "DirectorSearchRequest";
break;
case "manufacturer":
$mode = "electronics";
$MyFunc = "ManufacturerSearchRequest";
break;
}
//htmlentities - Convert all applicable characters to HTML entities
$params = array(
$ServiceType => htmlentities($_POST['query']),
'page' => 1,
'mode' => $mode,
'tag' => 'Webservice-20',
'type' => 'lite',
'devtag' => 'D8ZC6J75CUFJC' // the token I got from Amazon
);
// invoke the method
$MyResult = $proxy->$MyFunc($params);
/* if you are interested to see the contents of SOAP envelop that has exchanged, uncomment the following two lines of codes.*/
echo '<xmp>'.$proxy->request.'</xmp>';
echo '<xmp>'.$proxy->response.'</xmp>';
// uncomment following lines to view the result
print_r($MyResult);
$MyTotal = $MyResult['TotalResults'];
$MyItems = $MyResult['Details'];
// format and display the results
?>
Search for <b><? echo $_POST['query']; ?></b> returned <? echo $MyTotal; ?> matches from Amazon.
<p>
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<?
// parse the $MyItems[] array and extract the necessary information to display
foreach ($MyItems as $i)
{
?>
<tr>
<td align="center" valign="top" rowspan="3"><a href="<? echo $i['Url']; ?>"><img border="1" src=<? echo $i['ImageUrlSmall']; ?>></a></td>
<td><font size="-1"><b><? echo $i['ProductName']; ?></b> /
<?
if (is_array($i['Authors']))
{
//Join array elements with a string
echo implode(", ", $i['Authors']);
}
else if (is_array($i['Artists'])) //Finds whether a variable is an array
{
echo implode(", ", $i['Artists']);
}
else if ($i['Manufacturer'])
{
echo $i['Manufacturer'];
}?>
</font></td>
</tr>
<tr>
<td align="left" valign="top"><font size="-1">List Price: <? echo $i['ListPrice']; ?> / Our Price: <? echo $i['OurPrice']; ?></font></td>
</tr>
<tr>
<td align="left" valign="top"><font size="-1"><a href="<? echo $i['Url']; ?>">Read more at Amazon</a></font></td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<?
}
?>
</table>
<?
}
?>
</body>
</html>
|