如何建立友谊关系

编程入门 行业动态 更新时间:2024-10-24 18:25:52
本文介绍了如何建立友谊关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直试图找出如何做到这一点,甚至在看其他例子的时候,我无法弄清楚,所以也许我可以得到一些个性化的帮助。

I have been trying to figure out how to do this, and even with looking at other examples, I can't get it figured out, so maybe I can get some personalized help.

我有两张表, users_status 和 friendships 。

在 users_status 表中,我有一个字段 userid 和其他几个。 在 friendships 表中,我有字段 request_to , request_from 和 friendship_status 。

In the users_status table I have a field userid, and several others. In the friendships table, I have the fields request_to,request_from, and friendship_status.

基本上我想做的是获取所有状态信息由当前用户和当前用户的朋友(我可以在PHP中使用$ userid变量指定)。

Basically what I want to do is get all of the status posts by the current user AND those who are friends of the current user (which I can specify in my PHP using a $userid variable).

这里是一个例子, c $ c> friendships 表结构。当发送好友请求时,发件人和接收者的用户名被放置在表中,其中friend_status为0.当请求被接受时,将将友谊状态设置为1,然后将这两个当成是朋友。

Here's an example of the friendships table structure. When a friend request is sent, the userid of the sender and receiver are placed in the table, with a friendship_status of 0. When the request is accepted, the friendship_status is set to 1 and those two are now friends.

friendship_id request_from request_to friendship_status 1 111248 111249 1 2 111209 111249 1 3 111209 111248 0 11 111209 111259 1 5 111252 111209 1 12 111261 111209 1

我意识到这可能不是确定友谊的最佳结构,特别是因为网站是基于关系的,必须检查友谊连接将是一个经常使用的事情。

I realize this may not even be the best structure for determining friendships, especially since the site is relationship based and having to check for friendship connections will be a frequently used thing.

对于 friend_requests 和 friendships 两个单独的表可能会更好吗?如果是这样,我如何构建/管理友谊表?

Would it perhaps be better to have two separate tables for friend_requests and friendships? If so, how would I structure/manage the friendships table?

推荐答案

您可以使用表格连接(例如 http://dev.mysql。 com / doc / refman / 5.0 / en / join.html )查找所有请求。

You can use a table join (e.g. dev.mysql/doc/refman/5.0/en/join.html) to find all of the requests.

其实你可以在这里使用一个子查询: p>

Actually you can use a subquery here:

SELECT * FROM users_status WHERE userid = "$userid" OR userid in (SELECT request_to FROM friendships where request_from = "$userid" AND friendship_status = 1) OR userid in (SELECT request_from FROM friendships where request_to = "$userid" AND friendship_status = 1)

将 $ userid 替换为您的用户ID

replace $userid with your user id

更多推荐

如何建立友谊关系

本文发布于:2023-10-30 23:54:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:友谊   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!