Jump to content

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 ):

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.