i am making a friend system for a social networking kind of website.i have completed the search part now i am working on adding friends.so when a logged in user visits a other guy's profile he can send him friend request.so on clicking the button i am taking two parameter one is friend's id and other is user's id and passing it to the model.my tables are user_login for users and friends have 1)user_id1 2)friend_id1 and so on.so now i want to pass my data that i have recieved after clicking on the add friend button to the database and for that i have to join the two tables.i.e user_login and pivot table friends.so thaton clicking these id's get saved in that pivot table.just wanted someone to help me with the joining of tables.since it is showing me error. my code for model is
public function display_followers($user_id,$friend_id)
{
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('id',$user_id);
$this->db->where('id',$friend_id);
$this->db->join('friends', 'users_login.id = friends.user_id');
$this->db->join('friends', 'users_login.id = friends.friend_id');
$query=$this->db->get();
if($query->num_rows()>0){
return $query->Result();
}
else{
return false;
}
}
}
my code for controller is
public function followers(){
$friend_id=$this->uri->segment(3);
$user_id = $this->session->userdata['logged_in']['id'];
$this->load->model('Main_Model');
$this->Main_Model->display_followers($user_id,$friend_id);
}
user_login
JOINuser_login
ONusers_login
.id
=friends
.user_id
JOINuser_login
ONusers_login
.id
=friends
.friend_id
WHEREid
= '6' ANDid
= '1' Filename: models/Main_Model.php Line Number: 36 – anku Apr 12 '17 at 16:36