talhaMalik22
talhaMalik22

Reputation: 155

Notice: Trying to get property of non-object

i am facing this problem here. i want to show item's name by getting its item id from another table. following is the code
i am having problem when i try to show name using ".$obj[0]->name." in the first line of the for loop.

$objClass = array(); 
$objClass1 = array();
$obj= array(); 
$object = new product();
$objLogic = new customerLogic();
$objLogic1 = new customerLogic(); 
$objL= new productLogic();
$objClass[0]= new stdClass;
$objClass1[0]= new stdClass;
$obj[0]= new stdClass;
$objClass[0]->custId = $_GET['id'];
$objClass1[0]->custId = $_GET['id'];

$objClass = $objLogic->getSaleRecord_customer($objClass[0]);
$objClass1 = $objLogic1->getName_customer($objClass1[0]);
$object->itemId = $objClass[0]->itemId;
$obj =$objL->getName_product($object->itemId); 
// echo $objClass1[0]->firstName;
$i=1;
foreach($objClass as $customer ) {
    echo "<tr><td class=\"inner_text\">$customer->reciept</td><td align=\"center\">".$obj[0]->name."</td>";
    echo "<td align=\"center\">".$objClass1[0]->firstName."&nbsp;".$objClass1[0]->lastName."</td><td align=\"center\">";
    echo "$customer->weight</td>
    <td align=\"center\">$customer->costPerKg</td>
    <td align=\"center\">$customer->cost</td>
    <td align=\"center\">$customer->payed</td>
    <td align=\"center\">$customer->remaining</td></tr>";
    $i++;
}
?>
</table>

Upvotes: 2

Views: 32921

Answers (2)

Pekka
Pekka

Reputation: 449385

You are overwriting $obj:

$obj =$objL->getName_product($object->itemId); 

Upvotes: 0

Milad Naseri
Milad Naseri

Reputation: 4118

Are you completely sure that $objL->getName_product($object->itemId); yields an object?

Could you verify that?

I think the return value of $objL->getName_product($object->itemId); is not what you think it is.

You can check it by print_r($objL->getName_product($object->itemId)); which will give you a printout of the contents of that functions output.

Or maybe you are unintentionally overriding the contents of $obj?

Upvotes: 2

Related Questions