php - friend 系统php和mysql查询?

标签 php mysql

我想知道如何最好地为我的 friend 系统布局我的数据库?我本来打算这样做,

 id (int) | friendID (int) | accepted (enum)

我认为应该这样做,只有一个问题:

  1. 当用户确认请求时,我是否应该将当前行枚举更改为 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/

相关文章:

php - "Class ' Quote_Tag ' not found"Laravel Eloquent 多对多

migration - 更新到 PHP 5.3,禁用弃用函数警告

php - 从数据库更新单个图像(在数据库中,多个图像以逗号分隔的方式存储)

mysql - 为多个查询获取 rails ActiveRecord 而不是对象数组

mySQL:删除正则表达式子字符串

php - Laravel 5.5 试图获取非对象的属性 'id'

mysql - 57, 57 必须为 JOIN 表达式定义标识变量

php - 将 DOMDocument 中的特定元素导出到字符串

javascript - 如何在javascript中使用php代码

php - TinyMCE 画得不错,但不让我输入。在 FF 中,按钮有错误 : Component returned failure code: 0x80004005