Welcome Guest, Not a member yet? Register   Sign In
Codeigniter remove follow button after following user
#1

Hi I am able to display users friends on a page but when I into the friends profile I still see the follow button, is there anyway I can remove the button after following? I am using codeigniter. see code.
Model:

Code:
public function get_friends($user_id = NULL){
   if ($user_id = $this->session->userdata('user_id')){
   $this->db->select('*');
   $this->db->from('users');
   $this->db->join('friends', 'friends.user_id = users.user_id');
   $this->db->where('friends.user_id2', $user_id);
   $query = $this->db->get();
   return $query->result_array($user_id);
       }
}


Controller


Hi I am able to display users friends on a page but when I into the friends profile I still see the follow button, is there anyway I can remove the button after following? I am using codeigniter. see code.
Model


Code:
public function get_friends($user_id = NULL){
   if ($user_id = $this->session->userdata('user_id')){
   $this->db->select('*');
   $this->db->from('users');
   $this->db->join('friends', 'friends.user_id = users.user_id');
   $this->db->where('friends.user_id2', $user_id);
   $query = $this->db->get();
   return $query->result_array($user_id);
       }
}


Controller


Code:
public function view($user_id = NULL){
   $data['friends'] = $this->Friend_model->get_friends($user_id);  
   $this->load->view('user/templates/header_view_subpage');
   $this->load->view('user/members_entry_view', $data);
   $this->load->view('user/templates/footer_view_subpage');

}

View



Code:
<?php
    $session = $this->session->userdata('user_id');
    $friends = $this->session->userdata('user_id2');
    if($session == $members['user_id']):
?>
   <div class="col-md-6">
   <button type="button" class="btn btn-primary btn-sm btn-block"><i class="fa fa-envelope"></i> Send Message</button>
   </div>
 <div class="col-md-6">
[color=#242729][size=small][font=Monaco, Consolas, Courier, monospace]    <button type="button" class="btn btn-primary btn-sm btn-block"><i class="fa fa-add"></i> Follow</button>[/font][/size][/color]
   </div>
<?php
endif;
?>


Attached Files Thumbnail(s)
   
Reply
#2

You're passing $data['friends'] to your view. But in the view, you immediately overwrite $friends with some session variable 'user_id2'. So, the friends from your model aren't recognized.
Reply
#3

(08-07-2017, 07:27 AM)Wouter60 Wrote: You're passing $data['friends'] to your view. But in the view, you immediately overwrite $friends with some session variable 'user_id2'. So, the friends from your model aren't recognized.

You are right there, but you see in the view when I use $friends['username']; it throws an error saying Message: Undefined variable: friends, even when friends is defined in the controller.
Reply
#4

You are not passing the $members[] array in the controller.

Something seems to be missing eitehr in your controller or view.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB