2017-04-12 57 views
-1

我想加入用戶表和朋友表。 我的用戶使用用戶名和密碼 而朋友表有user_id1和friend_id .problem是我會從使用用戶名的會話中接收用戶ID,但我將如何接收我想添加/關注的朋友的ID。用戶點擊添加朋友按鈕。我想要接收兩個參數的用戶參數和朋友參數。也請幫助我與樞軸表的加入代碼,我將如何加入用戶表和朋友ID列與用戶表..任何提示將會有所幫助。朋友和用戶表

+0

https://dev.mysql.com/doc/refman/5.7/en/join.html –

+0

如何將我收到的點擊添加好友button.plz讓我知道了朋友的參數。 –

+0

@anmolhans你怎麼得到你有任何代碼? –

回答

0

Users 

id | name | email | details 
---------------------------- 
1 | abc | [email protected] | some detail 
2 | def | [email protected] | some detail 

Friendship 

id | user_id | friend_id 
----------------------------- 
1 | 1  | 2 
2 | 2  | 1 

在已顯示的用戶一起添加友情鏈接視圖。你也會從中你已經使用迭代的用戶,例如

<?php foreach($users as $user) {?> 
    <h2><?php echo $user->name?></h2> 
    <a href="<?php echo base_url().'users/addtofriend/'.$user->id?>" class="btn btn-info"> Add to Friend </a> 
<?php } ?> 

在您的控制器功能,你可以從會話中獲取的用戶ID的循環,並且用戶通過該用戶的ID被添加到朋友從網址像

function addtofriend() 
{ 
    $userId=$this->session->userdata['id']; 
    $friendId=$this->uri->segment(3); 
    // Call your model function 
    $this->user_model->addFriend($userId,$friendId); 
} 
+0

我會從會話中獲取用戶ID,但如何在點擊添加朋友按鈕後收到朋友ID,這是我主要關心的問題。 –

+0

你從來沒有在URL中傳遞值? –

+0

哦對不起 –