English 中文(简体)
如何使用 MMSQL 跟踪用户喜欢的用户
原标题:How to use MYSQL to track user likes
  • 时间:2012-05-25 06:18:14
  •  标签:
  • mysql

如何使用 MySQL 追踪别人喜欢的文章?

It seems simple enough to just keep track of the total number of likes. The part I don t understand, is how to 1. keep users from only voting on something once and 2. allow users to click on their profile to see the stories they have liked.

您是否在表格中有一个专栏, 包含您刚刚添加的逗号分隔用户名中的故事信息? 您可以跟踪谁喜欢一个故事, 但数据会变得巨大, 特别是对于有十万用户以上的网站。 您将如何允许用户查看他们喜欢的所有故事?

谢谢

问题回答

每条需要一列。 不要使用逗号分隔列表 。


1. 如何使用户不只对某事投票一次

在 artid, userid 上创建唯一的索引 。


如何让用户看到他们喜欢的所有故事?

SELECT articleid FROM likes WHERE userid = 42

但数据会变得巨大

是的, 它可能会变得巨大。 大多数网站将很容易处理一个单一的数据库。 非常大的网站需要使用一个集群将数据存储在多个机器上。 数据需要分割, 以便应用程序知道在哪个服务器上找到数据 。

In Social Network these days are like the Graph dataStructure. Where every entity like people,photo,video,status-updates, comments etc are nodes of the graph and likes,unlikes are connections between two nodes.

ideally you would have a Table for Likes where you would just add a like. where you would store who liked, what is liked in columns and other info.

复杂的社交网络所做的不仅仅是这些。

您可以用两个栏目( story_id 和 user_id) 将喜欢的东西存储在叫做故事类的分层表格中。

1) Put a constraint in the database that the combination of these should be unique. That way your user can like a story only once.
2) You can pull the stories that the user likes from this table and pull other story details using the story id you have. 100,000 rows is not that big for a MYSQL database.

您也可以允许您的用户通过为 State=ENUM ( NAMED, Disliked ) 设置专栏来厌恶一个故事 。





相关问题
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 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签