php - 好友关注/取消关注表结构#MySQL

标签 php mysql pdo

目前当前功能如下:

用户好友

friend_iD | friend_One | friend_Two | Role |

friend_iD : int(11) AUTO_INCREMENT.
friend_One: int(11).
friend_Two: int(11).
Role: VARCHAR(5).

一旦我第一次注册,以下内容将被插入到 userFriends 表中(在本示例中,我自己将使用 iD 2)。

friend_iD | friend_One | friend_Two | Role |
    15          NULL         NULL       me

如果我正在访问 ID 为 1 的 John 的个人资料,并且单击[关注]按钮,则以下内容将插入到 userFriends 表列中。

friend_iD | friend_One | friend_Two | Role |
    20            2           1         fri

iD 1 : John
iD 2 : Gabby(Myself)

现在这意味着我是 friend _iD 为 2 的一个正在关注 iD 为 1 的 John。

Gabby[2] > John[1]

<强>1。对于关注系统来说,这是一个很好的表结构吗?

<强>2。如果不是,我可以改进什么或者有机会让它更快或者 更好,我怀疑这样的性能会有任何问题 简单的功能。

最佳答案

Once I first register, the following will be inserted into the userFriends table 
(In this example I will be using iD 2 for myself).

您需要为用户创建一个单独的表,例如

users
user_id | username | password | active | etc (email and another info)

然后您需要像您的设计一样创建follow

follow
friend_id | follower_user_id | followed_user_id

我不知道角色字段在您的设计中有何用途。如果需要的话添加即可

关于php - 好友关注/取消关注表结构#MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17437650/

相关文章:

mysql - 如何将 XML 转换为 SQL?

php - 通过 Cron 调用函数在其中做很多事情的解决方案?

php - PDO 即使没有绑定(bind)任何参数仍然会得到结果

php - 用表格条目加一填充文本框?

php - 单元测试 Laravel 5 时无法测试重定向

php - 警告 : Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\project\advancebrowsing. php:132)

mysql - LOAD DATA LOCAL INFILE 命令不导入任何数据

php - PDO 在 while 循环内运行查询只显示 1 个结果

php - 如何在 PHP 和 MySQL 中使用 PDO 将一行的结果分配给不同的变量

php - Laravel : add new row in model table