Welcome Guest, Not a member yet? Register   Sign In
Simple array question
#1

[eluser]markanderson993[/eluser]
Hey, I've got a simple question for you, so here goes!

I have a function that builds an array and returns it. The only problem is I keep getting the same error. Here's what I've got. Does anybody know how to make the bad man stop? :/

Code:
function get_friends($user_id)
    {
        $array = array();
    
        $this->db->where('user_id',$user_id);
        $get_friends_rows = $this->db->get('friends');
        
        if ($get_friends_rows->num_rows() > 0)
        {
            foreach($get_friends_rows->result() as $row)
            {
                $array[] = $row->friend_id;
            }
        }
        
        $this->db->where('friend_id',$user_id);
        $get_friends_rows = $this->db->get('friends');
        
        if ($get_friends_rows->num_rows() > 0)
        {
            foreach($get_friends_rows->result() as $row)
            {
                $array[] = $row->user_id;
            }
        }
        
        return $array;
        
    }

And here is how I apply it in my view

Code:
<?=$friends_array = $this->friends_model->get_friends($this->uri->segment(3))?>
            
            <? foreach($friends_array->result() as $row): ?>
                <?=$row?>
            <? endforeach; ?>

And this is the error I get

Quote:Array
Fatal error: Call to a member function result() on a non-object in .../application/views/includes/user/profile_image_include.php on line 72

Any help would be greatly appreciated!!!

- Pianoman993
#2

[eluser]Colin Williams[/eluser]
just iterate on $friends_array, not $friends_array->result()

I think you are confusing normal arrays with AR query results
#3

[eluser]markanderson993[/eluser]
Your a genius!
#4

[eluser]Colin Williams[/eluser]
Ha. Not really. It's pretty straight-forward.
#5

[eluser]TheFuzzy0ne[/eluser]
He's still got a valid point though.




Theme © iAndrew 2016 - Forum software by © MyBB