Jump to content

Invalid argument supplied for foreach()


jamespi

Recommended Posts

Hey folks,

 

I'm hoping someone may be able to provide me with some pointers on this.

I'm also not quite sure whether this is the correct location in the forum to post this as it relates to querying an SQL database too...

 

Anyway, basically I'm working with the following code:

 

$q = "SELECT * FROM #__db_product,#__db_product_price WHERE product.product_id = product_price.product_id AND product_publish = 'Y' ORDER BY {$orderby}";

$database->setQuery( $q, 0, $info[ 'count' ] );

$rows = $database->loadObjectList();

foreach ($rows as $row ) {

    ...

But when I run it I get the "Invalid argument supplied for foreach()" error message.

I know it is to do with the fact I'm querying 2 tables but I dont quite know what the best method would be to go about achieving this or at least fixing the fault that the foreach command is encountering.

 

Any kind soul able to shed some light on this? It would be much appreciated.

 

Thanks in advance

James

Link to comment
https://forums.phpfreaks.com/topic/151569-invalid-argument-supplied-for-foreach/
Share on other sites

Basically $database->loadObjectList(); isn't passing an array

 

can you add the following to give some more info

$rows = $database->loadObjectList();
var_dump($rows); //add this
foreach ($rows as $row ) {

and you post the message you get back (just before the "Invalid argument supplied for foreach()")

Thanks for the replies.

 

It would appear that the array isn't being passed.

When I use var_dump($rows); I just get a NULL error come up and using print_r($rows); gives the the original error again.

I know the 2 tables I have in the DB query are correct as individually they return results but as soon as I combine/join the 2 it breaks the array.

Frustrating ):

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.