Jump to content

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.

Edited by mac_gyver

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 by ChrisCwmbran
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.