怎么只用一行数据表示两个人的好友关系?

WBOY
Release: 2016-06-06 20:36:51
Original
1221 people have browsed it

user_id f_id dateline
1 2 time
2 1 time

现在是这样的方法。
SQL如下:

获取我的好友:

<code>sql</code><code>select * from frieds where user_id = :id or f_id= :id
</code>
Copy after login
Copy after login

怎么用一行数据来表示用户关系?

回复内容:

user_id f_id dateline
1 2 time
2 1 time

现在是这样的方法。
SQL如下:

获取我的好友:

<code>sql</code><code>select * from frieds where user_id = :id or f_id= :id
</code>
Copy after login
Copy after login

怎么用一行数据来表示用户关系?

新增一列用来表明两人友好关系
比如用数字(0,1,2),表示两人的关系(陌生,认识,熟知)

新建表 relation

<code>字段 id tinyint auto_increment primary key
字段 relation varchar 
</code>
Copy after login

user_id_1 user_id_2 relation
a b 1
a c 2
a d 3

relation: 1表示user_id_1是user_id_2的好友,2表示user_id_2是user_id_1的好友,3表示user_id_1和user_id_2互为好友.

稍微优化一下relation的表示值的话,可以这个样子表示01,10,11表示两个人的好友关系

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template