PHP Error

  • Thread starter Thread starter Faevilangel
  • Start date Start date
F

Faevilangel

I like to dabble in PHP and am dabbling with a soap based php script, and getting an error that I can't fix.

Warning: Invalid argument supplied for foreach() in /home/garethgi/public_html/aws/books.php on line 120

The code for the error is:

Code:
foreach ($items as $i)
{ 
?>
<tr>
<td align="center" valign="top" rowspan="3"><a href="book_detail-<? echo $i['Asin'].".php";
?>"><img border="0" src=<? echo $i['ImageUrlSmall']; ?>></a></td>
<td><font size="-1"><b><a href="books_detail-<? echo $i['Asin'].".php";
?>"><? echo $i['ProductName']; ?></a></b> / <? echo
implode(", ", $i['Authors']); ?></font></td> </tr> <tr> <td align="left"
valign="top"><font size="-1">Retail Price: <strike><? echo $i['ListPrice']."</strike> <b>Our Discount Price: ".$i['OurPrice']; ?></b> USD  </font></td> </tr> <tr> <td
align="left" valign="top"></td> </tr> <tr>
<td colspan=2>&nbsp;</td> </tr> 
<?php } ?>

Any help would be appreciated
 
what is in the $items array?
stick in print_r($items); just above to check...

Alasdair

Nothing is displayed which means that my script isn't grabbing the intended data.... Hmm

Thanks Alasdair... Gives me something to work from.
 
Upvote 0
what does...

echo $items[0];

give you?

Are these global vars?

Still nothing.

Here is the code for $items

$items = $result['Details'];

which I believe means it's grabbing data from $result, which the code is

$result = $proxy->KeywordSearchRequest($params);


The code I am using, is grabbing data from the amazon.co.uk website using SOAP and displaying with php.
 
Upvote 0
Its throwing the foreach error because the $items variable is empty.

Code:
<?php $items = array('apples', 'bananas', 'oranges'); print_r($items); ?>

<?php foreach($items as $item): ?>
<tr>
    <td align="center" valign="top" rowspan="3"><a href="book_detail-<?php echo $item['Asin'] . ".php"; ?>">
        <img border="0" src="<?php echo $item['ImageUrlSmall']; ?>"></a>
    </td>
    
    <td>
        <font size="-1">
            <b><a href="books_detail-<?php echo $item['Asin'] . ".php"; ?>"><?php echo $item['ProductName']; ?></a></b> / <?php echo implode(", ", $item['Authors']); ?>
        </font>
    </td> 
</tr> 

<tr> 
    <td align="left" valign="top">
        <font size="-1">Retail Price: <strike><?php echo $item['ListPrice'] . "</strike> <b>Our Discount Price: " .$item['OurPrice']; ?></b> 
            USD  
        </font>
    </td> 
</tr> 

<tr> 
    <td align="left" valign="top"></td> 
</tr> 

<tr>
    <td colspan="2">&nbsp;</td> 
</tr> 

<?php endforeach; ?>
This works because now the $items variable contains apples, bananas and oranges so the foreach statement has data to work with.

Scott.
 
Last edited by a moderator:
Upvote 0
I'm back with this. Decided to strip the code right back and try again, and now I have another error!

Code:
[B]
Fatal error[/B]:  Call to a member function BrowseNodeSearchRequest() on a non-objec

The error is coming from
Code:
$books  = $client->BrowseNodeSearchRequest($params);

$client is initialised by
Code:
 $client = $WSDL->getProxy();
[/code[

I found the following which may explain the issue but it goes way over my head.

[QUOTE]If you look at your error "Call to a member  function on a non-object" and then look at the line number you can see  it is trying to call the function "BrowseNodeSearchRequest(...)" from  the object $client. However, $client is never being initialised as an  object which is why you're getting the error. 		[/QUOTE]

Any ideas guys?
 
Upvote 0
Still nothing.

Here is the code for $items

$items = $result['Details'];

which I believe means it's grabbing data from $result, which the code is

$result = $proxy->KeywordSearchRequest($params);


The code I am using, is grabbing data from the amazon.co.uk website using SOAP and displaying with php.
Try changing = to ==. Might fix it.
 
Last edited:
Upvote 0
Try changing = to ==. Might fix it.

That will just give you a load more errors, I thought you were supposed to be a developer!

= assigns the value on the right to the value on the left (which is the intention here)

== is a comparison

Anyway if it's SOAP work right back and if possible check the SOAP message you send to Amazon, then check the content of the response. With it been Amazon do you send the SOAP requests to a secure https address or just standard http? If standard http you could use an IP Packet Sniffer to monitor the communications, not if its https.

With it being Amazon I expect the documentation should be reasonable or certainly a lot of discussion online, double check all your code against examples. Start at the beginning and keep working through printing variable values out to the screen.

You need to take a methodical approach, if you keep bouncing around different parts of the code you can keep missing the error.
 
Upvote 0
That will just give you a load more errors, I thought you were supposed to be a developer!

= assigns the value on the right to the value on the left (which is the intention here)

== is a comparison

Anyway if it's SOAP work right back and if possible check the SOAP message you send to Amazon, then check the content of the response. With it been Amazon do you send the SOAP requests to a secure https address or just standard http? If standard http you could use an IP Packet Sniffer to monitor the communications, not if its https.

With it being Amazon I expect the documentation should be reasonable or certainly a lot of discussion online, double check all your code against examples. Start at the beginning and keep working through printing variable values out to the screen.

You need to take a methodical approach, if you keep bouncing around different parts of the code you can keep missing the error.

I found an article with the same code I was using, but I get errors with it (see last post).

The code can be found here. The Amazon soapclient url is right, I am thinking it might be that Amazon have changed the name of the requests but I can't find anywhere it lists the soap lists.
 
Upvote 0
That will just give you a load more errors, I thought you were supposed to be a developer!

= assigns the value on the right to the value on the left (which is the intention here)

== is a comparison

Anyway if it's SOAP work right back and if possible check the SOAP message you send to Amazon, then check the content of the response. With it been Amazon do you send the SOAP requests to a secure https address or just standard http? If standard http you could use an IP Packet Sniffer to monitor the communications, not if its https.

With it being Amazon I expect the documentation should be reasonable or certainly a lot of discussion online, double check all your code against examples. Start at the beginning and keep working through printing variable values out to the screen.

You need to take a methodical approach, if you keep bouncing around different parts of the code you can keep missing the error.
Not a developer as such. Just something I like to do in my spare time.

I never get = and == the right way around so usually do it by trial and error.
 
Upvote 0

Latest Articles