1

我的问题是,我们如何将统计信息与帖子相关联,例如,点赞数如何与每个 Facebook 帖子唯一关联,或者与 Stackoverflow 上的问题相关联的点赞和点赞统计信息。进一步详细说明,假设在 stackoverflow 上有一个问题,我单击 Upvote 按钮,系统如何识别单击 upvote 按钮以将统计信息发送到后端数据库的问题?由于每个问题都是由用户动态生成的,如何给与每个问题相关联的按钮一个唯一的 ID 呢?

4

1 回答 1

1

In the DB you would have an auto-incrementing ID field, when a question is generated and inserted into the db it is given an ID automatically, and in php + mysql you can get this id with the function mysql_insert_id().

Then when you output the html for the question, you add the id of the question into the html somehow.

It can be in a hidden field in a html form eg <input type='hidden' name='questionid' value='52'></input> and then have it accessible in $_POST or $_GET in the php

or as part of the id or name of another element having an element with id or name of upvote52 and then you either extract it from the id/name via javascript before POSTing it to the php or you can just send it like that to the php and extract the ID from the rest of the string in the backend

or if its a anchor tag you can add it to the href as a paramater eg mysite.com/upvote.php?question=52 and then access it via $_GET in the php

于 2012-08-29T06:09:45.660 回答