Welcome Guest, Not a member yet? Register   Sign In
Database Class : Traversing Objects
#1

[eluser]Unknown[/eluser]
Hi,

I'm new to php & codeigniter. My code below has got a problem but I really cannot figure out where went wrong...It seems the result() or row() cannot produce an object. Could anyone help me on this ?

* Line 25 is
Code:
if ($qco->Gateway_Boo == 1) {

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Trying to get property of non-object</p>
<p>Filename: models/Tp_model.php</p>
<p>Line Number: 25</p>

Code:
function Tp_coordinator($tpid) {  $bk_content = array();  $qco_pre = $this->db->get_where('tp_summary',array('TemplateID'=>$tpid)); $qco = $qco_pre->row();  if ($qco->Gateway_Boo == 1) { $bk_content[0] = $this->_Tp_gateway_lookup($tpid); } else { $bk_content[0] = '-';  }

Thank you.
#2

[eluser]danmontgomery[/eluser]
Don't believe in newlines? -.-

You have to call result() to get an object before you can call row().

Code:
$qco = $qco_pre->result()->row();
#3

[eluser]Kosonome[/eluser]
Usually I got this error when I try to access something don't exist in a object.
Maybe $qco_pre->row() isn't returning anything (not even an object).

You can check that doing:
Code:
if ($qce->num_rows() > 0) {
    //do something
} else {
    //nothing returned
}

And I guess you can $qce->row() without using $qce->result() before.
#4

[eluser]Unknown[/eluser]
THANKS ALL ! :lol:

Check by num_rows() helps a lot and it seems one always needs to use foreach to access query results.




Theme © iAndrew 2016 - Forum software by © MyBB