Jump to content

Notice: Trying to get property of non-object


ChrisCwmbran

Recommended Posts

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.

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.

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.

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.