0

I got the following message:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: models/usermodel.php

Line Number: 4146

and here is my function where the line 4146 is:

else if($resultRes->average<'3' &&  $resultRes->average>='2')

This is the full function code. I have the same message for line 4137, 4140, 4143, 4146 and 4149

function get_Ranking($resid=''){
$sql="select ((Qrating+Srating+Drating+Crating)/4) as average from testimonial where RestId=".$resid;
$query=$this->db->query($sql);
$resultRes=$query->row();
if($resultRes->average == '5'){
return '050';
}
else if($resultRes->average<'5' &&  $resultRes->average>='4'){
return '040';
}
else if($resultRes->average<'4' &&  $resultRes->average>='3'){
return '030';
}
else if($resultRes->average<'3' &&  $resultRes->average>='2'){
return '020';
}
else if($resultRes->average<'2' &&  $resultRes->average>='1'){
return '010';
}

else{
return '000';
}
}

How can i fix it?

1
  • Are you sure you are getting the records from the database properly Commented Nov 8, 2013 at 12:39

3 Answers 3

3

It's because some of your queries are empty.

if($query->num_rows() != 0)

first

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

1 Comment

I was getting this warning & trying to find solution but no luck. Thanks dear
0

Try with

if($resultRes[0]['average'] == '5'){
    return '050';
}
else if($resultRes[0]['average'] < '5' &&  $resultRes[0]['average'] >= '4'){
    return '040';
}

Since it will return an single row only,You can either use $resultRes['average'] directly.

Comments

0

Try to print the $resultRes before getting average from it.

$resultRes=$query->row();
printr($resultRes);

also print the last query and check whether your parameters are correctly populated in the query using below query.

echo $this->db->last_query();

It can be the case your parameter is empty and no record retrieved from table.

2 Comments

It seems not working properly my function, because i write the print_r($resultRes); and it does´nt work, it does'nt show anything on my screen, i will review other files, because everything is ok in my database. Thanks anyway and i will post later if i get some result.
Please check the query by using echo $this->db->last_query(); after running the query. Then you can execute the query directly and check what is the result returned.

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.