我想知道您将如何使用 PHP 和 MySQL Friends 系统?
我在想,在 users
表中会有一个名为 friends
的列,它会保存与其他用户 ID 的数据,他们是 friend ,用逗号分隔,
例如,1,3,56,3
- 然后分解它并 foreach 数组?
这行得通吗?
最佳答案
这是一种方法。
您可能需要考虑为每个 friend 创建一个新行。
例如:
好友 ID:1 friend 姓名:鲍勃
好友 ID:2 friend 姓名:罗恩
好友 ID:3 friend 姓名:乔
如果 Bob 是 Ron 和 Joe 的 friend ,那么 friends 表中会有 2 条记录
id user friend
1 1 2
2 1 3
然后如果 joe 和 bob 成为 friend 但不是 ron table 最终会是
id user friend
1 1 2
2 1 3
3 3 1
这使您可以灵活地添加更复杂的查询。
关于php - MySQL Relational friends scheme?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5720391/