English 中文(简体)
php 友善制度
原标题:php friending system
  • 时间:2011-10-14 18:49:29
  •  标签:
  • php
  • sql

如果有人能帮助我解决这一问题,我会不胜感激。

我制作一个网站,希望登记用户能够作为朋友相互补充。

此人必须“邀请”另一个注册用户(数据库)。 另一人将收到某种通知。 如果当事人无视通知,就没有发生,而且当他/她批准时,他们是朋友。

现在我有一个想法,将使用表一米:

+----------------------------------------+
|               Requests                 |
+----------------------------+-----------+
| id | user_from |  user_to  |   status  |  
+----+-----------+-----------+-----------+
|    |           |           |           |
|    |           |           |           |
|    |           |           |           |
|    |           |           |           |
+----------------------------+-----------+

正如我说过的那样,这只是我想要使用的一种想法,但我不知道,如果我有把一个人作为朋友联系起来的话,该法典将是什么。

我认为,行政部门应核准所发出的请求,并在用户批准或不批准时批准。 我不知道该表将如何看待。

我设想利用INNER JOIN作为朋友“加入”这两个用户。 英国广播公司再次肯定如何做到这一点。 这是否出现在我的营地? 让我们说朋友。 php?

SELECT name, email FROM users

INNER JOIN friends ON users.id = friends.user.id WHERE users.id = 1

正如我说过的那样,我对要做的事情有好的想法,但是,在编码时,我并不完全肯定如何这样做。

感谢!

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 您应有一个关系表,仅与用户联系起来。

+-----------------------------------------+
|               relationships             |
+-----------------------------------------+
| id | user_id1  |  user_id2   |  status  |
+----+-----------+-------------+----------+
|    |           |             |          |
|    |           |             |          |
|    |           |             |          |
|    |           |             |          |
+------------------------------+----------+

如果用户_id1和用户_id2均为用户。 注:我也许会把身份当作一个大事,如等待、拒绝、朋友和敌人。 我最初想的是使用ool子,但后来是否有其他理想地位? 和你一样,你也跟踪了破碎的友谊或某种其他关系。

Then you simply do a multiple where clause to determine friends: WHERE (user_id=:id OR friend_id=:id) AND status= friend

问题回答

• 提供你所希望的多种功能,即:

  1. User A requests to be User B s friend
  2. User B receives a notification of the friend request, and can accept, decline, or ignore
  3. Whenever User B accepts the request, they are friends

由于你的问题含糊不清,我只能提出建议,因为没有提出任何具体问题。

<>SQL Schema - 贵方认为适合朋友的要求。 你不妨澄清表格名称,因为请求可能是一个广泛的议题。 如果你确定用户——用户——一栏——的独特指数(这将防止向同一人重复提出朋友要求),那么你不一定需要一栏。 同样,这是你的选择,任何答案都不一定“正确”。 在地位领域,考虑使用申请有效国家的ENUM,例如ENUM(“PENDING”)“DECLINED”。

As far as notifications, the best way to do this is to insert a notification into a notifications table when a user initiates a friend request, instead of trying to derive a notification by checking for new friend requests. The first is more extensible, and allows you to raise notifications for a variety of reasons.

Finally, once the friend request succeeds, you can do one of two things:

  1. Remove the request from the friend requests table, and insert into a friends table
  2. Mark the request as accepted

Again, your choice on implementation here. Option #1 allows you to easily query out friends but yields an extra table and (possibly) two rows for each friendship, if that s how you choose to implement it. Option #2 requires you to query the requests table for requests that are completed, making your query slightly more complicated and IMO a bit less intuitive, since Friends and Friend Requests aren t necessarily related. In addition, you can add fields in the Friends table, such as a date that the friendship started, that wouldn t make sense in the Friend Requests table.

<>Queries——如果你需要找一个用户朋友,你可以做与以下内容相似的事情,这取决于你为你的Suca所作的决定:

SELECT * FROM friends WHERE user_id = $user_id
SELECT * FROM friends WHERE user_id = $user_id OR friend_id = $user_id
SELECT * FROM friend_requests WHERE (user_from = $user_id OR user_to = $user_id) AND status = "COMPLETED"




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签