jamespi Posted March 29, 2009 Share Posted March 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151569-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
MadTechie Posted March 29, 2009 Share Posted March 29, 2009 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()") Quote Link to comment https://forums.phpfreaks.com/topic/151569-invalid-argument-supplied-for-foreach/#findComment-796046 Share on other sites More sharing options...
taquitosensei Posted March 29, 2009 Share Posted March 29, 2009 do print_r($rows); just before the foreach to make sure that it's an array and that the data looks the way it should. Quote Link to comment https://forums.phpfreaks.com/topic/151569-invalid-argument-supplied-for-foreach/#findComment-796048 Share on other sites More sharing options...
jamespi Posted March 29, 2009 Author Share Posted March 29, 2009 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 ): Quote Link to comment https://forums.phpfreaks.com/topic/151569-invalid-argument-supplied-for-foreach/#findComment-796202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.