0

Everything seems to work just fine but I keep getting the following error:

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;
}
3
  • Can you add line numbers or highlight the involved line? Commented Feb 4, 2013 at 11:38
  • Would be helpful if we could see models/ordermodel.php Commented Feb 4, 2013 at 11:41
  • the involved lines are the return lines in the ordermodel. Commented Feb 4, 2013 at 12:12

2 Answers 2

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

It should be $row = $city->result, judging from your code. Moreover, it cannot throw a fatal error. Can you paste the error here?
0

Seem that your query has no results, try:

function get_company_name($ordernumber) {
    $this->db->where('order_number', $ordernumber);
    $companyname = $this->db->get('order');

    if ($companyname->num_rows() > 0) {
        return $companyname->row()->company_name;
    }
    else {
        return '';
    }
}

2 Comments

It does have results and as i said - everything is working properly. It echoes the correct values but also shows an error.
object(stdClass)#80 (3) { ["order_number"]=> string(10) "ABCDE12345" ["city"]=> string(7) "glasgow" ["company_name"]=> string(13) "Great Company" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.