Welcome Guest, Not a member yet? Register   Sign In
I've looked everywhere to figure this out: CI returning a non-object
#1

[eluser]sehummel[/eluser]
I have this happen all the time and I'm never quite sure why it's happening. Here is the query in my model:

Code:
$query = $this->db->query('SELECT * FROM members WHERE email = "' . $this->session->userdata('email') . '"');
        return $query;

I try to output this in my view with:

Code:
foreach($query->result() as $row) {...echo $row->name, etc.}

But I get an error:

Code:
Fatal error: Call to a member function result() on a non-object ...

I ran the profiler and my query is valid and there is data in the database to be pulled. So what am I do wrong?

I'm told that if I pass an object to a view it becomes a keyed array. So what should I be passing and how should I output it. Please don't refer me to the documentation. I've read that and it's what I've tried. That's why I'm posting here. Thanks.
#2

[eluser]InsiteFX[/eluser]
Give this a try:
Code:
$row = $query->row_array();
return $row;

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB