PHP CodeIgniter: Trying to get property of non-object

codeigniter, php

PHP CodeIgniter: Trying to get property of non-object

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: models/ordermodel.php

Line Number: 24

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: models/ordermodel.php

Line Number: 31

================================================================

In the view i just echo $company_name

Controller:

            $city = $this->ordermodel->get_city($order_reference);            $customerCompanyName = $this->ordermodel->get_company_name($order_reference);            $data['company_name'] = $customerCompanyName;

Model:

function get_city($ordernumber) {    $this->db->where('order_number', $ordernumber);    $city = $this->db->get('order');    return $city->row()->city;}function get_company_name($ordernumber) {    $this->db->where('order_number', $ordernumber);    $companyname = $this->db->get('order');    return $companyname->row()->company_name;}

Best Solution

Use therresult() method, it should elimiate all of your errors

$row = $city->result(); return $row->city;