Welcome Guest, Not a member yet? Register   Sign In
Issue with data return
#1

[eluser]jbads[/eluser]
Hi, I may sound stupid here, I probably am. I've been struggling for hour with a function that gets a list of a persons contacts based on their userid and I would like it to retrieve certain data for each contact on that list.

This is my page view controller
eg:
Code:
//Get members contacts
    $data['contacts']        =    $this->_get_member_contacts($user_id);
        
    //Load Page
    $this->load->view('profile/profile_home_body_view', $data);

And this is the function
Code:
protected function _get_member_contacts($id){
    //Get a list of contact id's relating to members list
        $this->db->select('contact_id');
    $this->db->from('jcc_contacts');
    $this->db->where('user_id', $id);
    $query    =    $this->db->get();
    
    //Check there was a result else return false
    if($query->num_rows() > 0)
    {
    //For each result from that query, we need to get the info    
        foreach($query->result_array() as $row){
            
        //Get the data
        $this->db->select('jcc_users.id, jcc_users.username, jcc_user.user_display_name, jcc_user.user_display_email, jcc_user.user_location');
        $this->db->from('jcc_user');
        $this->db->join('jcc_users', 'jcc_users.id = jcc_user.user_id');
        $this->db->where('id', $row['contact_id']);
        $result        =    $this->db->get();
            
        $res    =    $result->row();
                
        //$data['contacts']                    =    $result->result_array();
                
        $data['contacts']['id']                =     $res->id;
        $data['contacts']['username']                =     $res->username;
        $data['contacts']['name']            =     $res->user_display_name;
        $data['contacts']['email']            =     $res->user_display_email;
        $data['contacts']['location']                =     $res->user_location;
                    
        }
        return $data['contacts'];

        }
        else
        {
            return FALSE;
        }
}
This particular version of my code only returns the last row in the DB.
I've tried every combination of result_array() and row() and row_array() etc I can think of. Its driving me insane because I know it's going to be something small that requires doing.

So If anyone can see what I'm trying to do here and can suggest a way of doing it, it would be greatly appreciated.

Cheers. Jake


Messages In This Thread
Issue with data return - by El Forum - 06-02-2008, 04:01 PM
Issue with data return - by El Forum - 06-02-2008, 05:14 PM
Issue with data return - by El Forum - 06-02-2008, 11:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB