Welcome Guest, Not a member yet? Register   Sign In
Friends count of my friends
#1

[eluser]JamieBarton[/eluser]
Hey

How are you all doing? Hope all is well.

After a little help, yet again on a query.

What I want to do is count the number of friends my friends have.

I'm using CI's Active Record, it can be written in a query too if necessary.

Basically, when I go to a profile I want to display the friends count of my friends, so in a list view for example:

<b>Friends</b>
- John (California, 30 friends)
- Sophie (United kingdom, 984 friends)

The code I have at the moment is:

Code:
function get_connected_friends($user_id)
{
  $this->db->select('friends.*, users.*, users.id AS friend_user_id');
  
  $this->db->join('users', 'users.id = friends.friend_id');
  
  $this->db->where('friends.user_id', $user_id);
  
  $this->db->where('friends.approved', 1);
  
  return $this->db->get($this->table());
}

My friends table structured:

id / user_id / friend_id / approved


Regards,
Jamie


Messages In This Thread
Friends count of my friends - by El Forum - 07-25-2012, 06:57 AM
Friends count of my friends - by El Forum - 07-25-2012, 07:40 AM
Friends count of my friends - by El Forum - 07-25-2012, 07:46 AM
Friends count of my friends - by El Forum - 07-25-2012, 07:59 AM
Friends count of my friends - by El Forum - 07-25-2012, 08:22 AM
Friends count of my friends - by El Forum - 07-25-2012, 08:41 AM
Friends count of my friends - by El Forum - 07-25-2012, 08:48 AM
Friends count of my friends - by El Forum - 07-25-2012, 09:08 AM
Friends count of my friends - by El Forum - 07-25-2012, 09:10 AM
Friends count of my friends - by El Forum - 07-25-2012, 09:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB