Amazon web api - product search -page navigation not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rekha_harnoor
Forum Commoner
Posts: 32
Joined: Mon Feb 19, 2007 3:17 am

Amazon web api - product search -page navigation not working

Post by rekha_harnoor »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi I am using php 5 amd apache2.

I am displaying product price for amazon. I am getting results for the first page but when I click next page again first page is getting displayed.

Please tell me what is the problem and my code is as follows:

Code: Select all

<?php
// include class
require('c:/nusoap-0.7.2/lib/nusoap.php');
// create a instance of the SOAP client object
$soapclient = new soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl",
true);

$category = 'DVD';
$searchtxt = 'Celtic Women';
$searchtxt = urlencode($searchtxt);
$page = 1;
$keyword = $searchtxt;

// create a proxy so that WSDL methods can be accessed directly
$proxy = $soapclient->getProxy();

// if a keyword is present, do a keyword search
$client = new soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl", true);
$params = array(

'keyword' => $keyword, 
'page' => $page,
'mode' => $category,
'type' => 'heavy',
'devtag' => '1448K5G6ZXH03DQ33W02'
);

$namespace = 'http://soap.amazon.com';
$action = 'http://soap.amazon.com';
$method = "KeywordSearchRequest";
$result = $client->call($method, array('KeywordSearchRequest' => $params),$namespace, $action);
$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%" 
border="0" cellspacing="5" cellpadding="0"> <?php
foreach ($items as $i)
{
?>
<tr>
<td 
align="center" valign="top" rowspan="3"><a href="<?php echo $i['Url'];
?>"><img 
border="0" src=<?php echo $i['ImageUrlSmall']; ?>></a></td>
<td><font 
size="-1"><b><?php echo $i['ProductName']; ?></b> / 
</font></td> </tr> <tr> <td align="left"
valign="top"><font 
size="-1">List Price: <?php echo $i['ListPrice']; ?> /
Amazon.com Price: <?php 
echo $i['OurPrice']; ?></font></td> </tr> <tr> <td
align="left" 
valign="top"><font size="-1"><a href="<?php echo $i['Url'];
?>">Read more 
about this title on Amazon.com</a></font></td> </tr> <tr>
<td 
colspan=2>&nbsp;</td> </tr> <?php } ?> </table>
<!-- next and 
prev page links -->
<?php
$pageCount = ceil($total/10);
?>
<table width="100%" 
cellspacing="0" cellpadding="5">
<tr>
<td align="left"> <?php if ($page != 1) {?> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo $page - 1; ?>&keyword=<?php echo $keyword; ?>">Previous page</a> <?php } ?> &nbsp; </td>
<td align="center">Page <?php echo $page; ?> of <?php echo $pageCount; ?></td>

<?php for($i = 1; $i <= $pageCount; ++$i) ?>
<?php { ?>
<td align="right"> &nbsp; <a href="<?php echo $_SERVER['PHP_SELF']; ?> ?page=<?php echo $i ?> &keyword=<?php echo $keyword; ?> ">Next page</a> </td> <?php } ?>
</tr> 
</table>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Perhaps because you set $page=1 instead of $page=(isset($_GET['page']) ? $_GET['page'] : 1 ;
rekha_harnoor
Forum Commoner
Posts: 32
Joined: Mon Feb 19, 2007 3:17 am

Post by rekha_harnoor »

Still the next page link is not working!!!!
rekha_harnoor
Forum Commoner
Posts: 32
Joined: Mon Feb 19, 2007 3:17 am

Post by rekha_harnoor »

Thanks a lot it finally worked with few modifications and thanks for your suggestions.
Post Reply