我在php中创建了一个朋友系统。名为friends 的表有3 列。第一个是friends_id,第二个是user_one,第三个是user_two。朋友(friends_id,user_one,user_two)。其中 user_one 和 user_two 是好友用户的 ID。
下面的一段代码打印了我朋友的朋友。
<?php
$friend_query = mysql_query(" SELECT `user_one`, `user_two` FROM `friends` WHERE `user_one`='$session_user_id' OR `user_two`='$session_user_id' ");
while($run_friend = mysql_fetch_array($friend_query)){
$user_one = $run_friend['user_one'];
$user_two = $run_friend['user_two'];
if($user_one == $session_user_id){
$user = $user_two;
}else{
$user = $user_one;
}
$friend_id = getuser($user, 'user_id');
$friend_query_two = mysql_query(" SELECT `user_one`, `user_two` FROM `friends` WHERE (`user_one`='$friend_id' and `user_two` != '$session_user_id') OR (`user_one`!='$session_user_id' and`user_two`='$friend_id' ) ");
while($run_friend_two = mysql_fetch_array($friend_query_two)){
$user_one_two = $run_friend_two['user_one'];
$user_two_two = $run_friend_two['user_two'];
if($user_one_two == $friend_id){
$user_two = $user_two_two;
}else{
$user_two = $user_one_two;
}
$friend_id_two = getuser($user_two, 'user_id');
echo $friend_id_two;
} //end while first
} //end while second
?>
我的代码工作正常,但是如何修改它以使其仅打印我朋友的朋友,而这些朋友恰好不是我的朋友?(因为我朋友的一些朋友,恰好也是我的朋友)。