gpt4 book ai didi

php - 如何选择共同的 friend

转载 作者:行者123 更新时间:2023-11-29 11:41:03 25 4
gpt4 key购买 nike

请我选择用户的共同好友,$my_id$_SESSION['user'];$user_id 是选定的用户。这是代码:

    <?php

include 'connect.php';

include 'functions.php';

$my_frnds = mysqli_query{$con, "SELECT * FROM friends WHERE one='$my_id' OR two='$my_id'"};
while($my_friends = mysqli_fetch_array($my_frnds)){
$one = $my_friends['one'];
$two = $my_friends['two'];

if($one == $my_id){
$user == $two;
} else
$user == $one;
}

$user_frnds = mysqli_query{$con, "SELECT * FROM friends WHERE one='$user_id' OR two='$user_id'"};
while($user_friends = mysqli_fetch_array($user_frnds)){
$user_one = $user_friends['one'];
$user_two = $user_friends['two'];

if($user_one == $my_id){
$users == $user_two;
} else
$users == $user_one;
}

?>

假设我的 friend 是 (1, 2, 3, 4, 5, 6, 7),用户 friend 是 (2, 4, 6, 7, 8, 9, 10),所以共同的 friend 是 ( 2, 4, 6, 7) 我的问题是如何让共同的 friend 出去并回显他们的 ID?抱歉,我犯了一个错误,这是原始编码

最佳答案

如果一个是您的 ID,两个是 friend 的 ID:

select * from friends 
inner join (select * from friends where one = $user_id) as temp on temp.two = friends.two
where friends.one = $my_id

关于php - 如何选择共同的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35772633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com