So I'm currently working with a following model system.
You follow this x-user and x-user may not follow you back.
I have been able to display the users that I'm following but I would like to display a text saying whether x-users follows me back as well or not.
For example I have this on my table:
id, user_id, friend_id, status, type.
and I'm calling these three methods in my controller function:
PHP Code:
// Already friends?
$data['relationship'] = $this->User_model->the_relationship($user->id);
// Get user followings
$data['following'] = $this->User_model->get_followings($user->id);
// Followings follows back Logged In user?
$data['followsback'] = $this->User_model->followsBack($user->id);
one checks if there's already a relationship between both users(logged in and x-user), the second one gets the x-users which the logged in user is following and the third method should display a text of "Follows you back" and/or "Does not follows you".
Here are the three methods in my model:
PHP Code:
// Relationship for users
public function the_relationship($id){
$this->db->select('*');
$this->db->from($this->relationship);
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('friend_id', $id);
$this->db->where('type', $this->type);
$query = $this->db->get();
if($query->num_rows() >= 1){
return $query->row();
} else {
return false;
}
}
// Get user followings
public function get_followings($id){
$this->db->select('*');
$this->db->where('user_id', $id);
$this->db->where('friend_id !=', $this->session->userdata('user_id'));
$this->db->where('type', $this->type);
$this->db->where('status', 'following');
$query = $this->db->get($this->relationship);
return $query->result();
}
// X user follows back Logged In user? --- HERE IS WHERE I'M HAVING TROUBLES
public function followsBack($id){
$this->db->select('*');
//$this->db->where('user_id', $id);
$this->db->where('type', $this->type);
$this->db->where('status', 'following');
$query = $this->db->get($this->relationship);
return $query->row();
}
What would be the correct way to display the text in the view?
Thanks in advance.
NOTE: Do you use Twitter?; the system is similar if not exactly to it. You can see your following users and can see a text of follows you as well depending on each single user.
I do Front-End development most of the time