ChrisCwmbran Posted May 2, 2013 Share Posted May 2, 2013 Hi all I have a fragment of code here that doesn't work and produces a "Notice: Trying to get property of non-object" warning. // // productID was passed so display product record // // Load product record relating to productID // $sql = "SELECT * FROM product WHERE productID = " . $_GET["productID"]; $db->setQuery($sql); $product = $db->loadObjectList(); // // Load relevant Manufacterer record // $sql2 = "SELECT * FROM manufacturer WHERE manufacturerID = {$product->manufacturer}"; $db2->setQuery($sql2); $manufacturer = $db2->loadObjectList(); It appears that in the second query that the reference to $product->manufacturer doesn't work, but I don't really understand why. Thanks in advance for reading this, and any responses. Chris. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 2, 2013 Share Posted May 2, 2013 (edited) the name of the $db->loadObjectList() method hints that it returns an array (list) of objects. what is it supposed to return (array, single object, true/false if it fails...) and what is it actually returning? also, you should be using one joined query to get the related information, not two separate queries. Edited May 2, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
ChrisCwmbran Posted May 2, 2013 Author Share Posted May 2, 2013 (edited) The manufacturer table only contains one record with a matching manufacturerID so should return a single record. Similarly the product table should only return a single record with a matching productID. Im only just learning so I have no idea how to do a joined query. Edited May 2, 2013 by ChrisCwmbran Quote Link to comment 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.