今晩、論理を理解しようとして頭がおならを少ししています。あるユーザーが 1 人のユーザーと共有している友達の数を数える必要があります。(共通の友人)
ユーザー ID と友人のユーザー ID を含むテーブルがあります。レイアウトの例を以下に示します。
最初の結果は、ユーザー 1 がユーザー 2 と友達であることを意味します
[ID] - [FriendsID]
1-2
1-3
1-4
1-15
2-1
2-4
3-1
3-4
4-1
4-2
4-3
4-15
5-15
15-1
15-5
15-4
PHP ページが読み込まれると、そのユーザー (User1 など) のフレンド リストが読み込まれます。これは、(2,3,4.15) の「FriendID」を返します。
次に、ユーザーと共通の友達が何人いるかを計算する必要があります。たとえば、次のようになります。
1 is friends with 2,3,4
2 is friends with 1,4
3 is friends with 1,4,15
This would mean that “2” shares ONE mutual friend with 1
This would mean that “3” shares TWO mutual friend with 1
等々
私の出力は [FriendID] [Count] である必要があります
フレンドIDはフレンドです
userID 1 と共通する友達の数を数える
(手書きデータ例)