|
Hi Everybody,
I am new to PHP so please bear with me .
I was studying about a particular script involving querying the Amazon database using the client and parsing the info obtained
The info I obtained was in the form
stdClass Object
(
[TotalResults] => 822
[TotalPages] => 83
[Details] => Array
(
[0] => stdClass Object
(
[Url] => http://www.amazon.com/...
[Asin] => 0596004478
[ProductName] => Google Hacks
[Catalog] => Book
[Authors] => Array
(
[0] => Tara Calishain
[1] => Rael Dornfest
)
[ReleaseDate] => 01 February, 2003
[Manufacturer] => O'Reilly & Associates
[ImageUrlSmall] => http://images.amazon.com/...
[ImageUrlMedium] => http://images.amazon.com/...
[ImageUrlLarge] => http://images.amazon.com/...[ListPrice] => $24.95
[OurPrice] => $17.47
[UsedPrice] => $15.95
)
.....
)
)
This was stored in a variable $hits. That was then parsed using the following code
The entire code for this is
<?php
require_once 'SOAP/Client.php';
$wsdl_url =
'http://soap.amazon.com/schemas3/AmazonWebServices.wsdl';
$WSDL = new SOAP_WSDL($wsdl_url);
$client = $WSDL->getProxy();
$params = array(
'manufacturer' => "O'Reilly",
'mode' => 'books',
'sort' => '+title',
'page' => 1,
'type' => 'lite',
'tag' => 'XXXX',
'devtag' => 'XXXXXXXXXXXXXX',
);
$hits = $client->ManufacturerSearchRequest($params);
foreach ($hits->Details as $hit) {
$ProductName = html_entities($hit->ProductName);
$Authors = join(' and ', $hit->Authors);
print <<< _HTML_
<div style="clear:left; width: 300px; padding:5px;
margin:5px; background:#ddd;">
<a href="$hit->Url"><image src="$hit->ImageUrlSmall"
alt="$ProductName" align="left"></a>
<b>$ProductName</b><br/>
By $Authors<br/>
Amazon.com Price: $hit->OurPrice<br/>
</div>
_HTML_;
}
?>
But this doesnt seem to run. It gives me a Invalid argument supplied for foreach() error.
I tried commenting out the _HTML_ here document and it worked fine. I am unable to debug what exactly is wrong with the here document. COuld any of you guys please help me out? I have almost spent 5hrs on researching this but have been unsuccessful.
Any suggestions would be appreciated
Thanks a lot
Avinash
Last edited by avinashp; 03-20-2005 at 06:38 PM..
|