我想知道如何最好地为我的 friend 系统布局我的数据库?我本来打算这样做,
id (int) | friendID (int) | accepted (enum)
我认为应该这样做,只有一个问题:
当用户确认请求时,我是否应该将当前行枚举更改为 yes,然后为确认请求的用户插入另一行?即;
1 | 4 | yes 4 | 1 | yes
或者有没有一种方法可以从一行中提取两种关系而不插入另一行?
即;
1 | 4 | yes
最佳答案
在这种情况下,我认为最好为每个 friend 插入两次,因为空间很便宜,而且您添加 friend 的频率可能比阅读 friend 的频率要低。但是,如果您想节省空间,您可以更改选择 friend 的方式:
select friendId from friends where id = $userId
到
select friendId, id from friends where id=$userId or friendId=$userId
然后在 php 端,您将检查friendId或id是否是当前登录的用户等。
关于php - friend 系统php和mysql查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897917/