Reviews/votes/Mood class functions What mechanism restricts members to be able to vote the most convenient?

Source: Internet
Author: User
Some like the review of the system, such as: The article below, showing: positive/negative comments such a button

That is, like the CSDN Forum article page ...
Useful for me [0] throw a brick [0]

Personal Understanding:
Click through AJAX/JQ this kind of send to PHP operation MySQL, put the praise/bad comment field +1

However, generally this type of east, are restricted to IP, or even a cookie only ...

If the positive/negative data do need to be very accurate without moisture

I would like to use a member login to review (voting bad)

Does MySQL need to suggest a separate review table?

There is a data architecture what better way, can limit members only to vote once?

What good advice do you have, please?


Reply to discussion (solution)

There are many ways to do this, and it is entirely possible to create a separate table. Record which post, which member, how many votes voted. What time to vote. IP or something.
Next time he is in the cast, according to the member ID, the post ID, can not find the voting status?

It's necessary to build a table, and more than one.
Because you may also have xx concern xx, xx is xx's friend and so on a series of needs
Need comprehensive consideration
What you are thinking now is the core of the SNS website (or the basic)

See below:

Voting Information table:

CREATE TABLE ' votes ' (   ' id ' int (one) not null auto_increment,   ' IP ' varchar (+) NOT NULL,   UID Int (one) not NUL L,   ' vid ' int (one) not null,   ' fstcreate ' timestamp not null DEFAULT current_timestamp on UPDATE current_timestamp,< C5/>primary KEY (' id ')) engine=myisam auto_increment=1 DEFAULT Charset=utf8



Article table

CREATE TABLE ' article ' (   ' id ' int (one) not null auto_increment,   ' article_title ' varchar () ' is not null,   ' Article_type ' int (one) is not null,   ' article_content ' longtext is not null,   ' article_author ' varchar () is not NULL,   ' article_click_count ' int (one) not null default ' 0 ',   ' status ' int (one) not null default ' 0 ',   ' likes ' int (one) DE FAULT ' 0 ',   ' unlikes ' int (one) ' default ' 0 ',   ' fstcreate ' timestamp not NULL default current_timestamp on UPDATE Curre Nt_timestamp,   ' lastmodify ' datetime DEFAULT NULL,   PRIMARY key (' id '),   fulltext key ' Fulltext_article_ Title ' (' Article_title ', ' article_content ', ' key_words ')) Engine=myisam auto_increment=119 DEFAULT Charset=utf8 Checksum=1 delay_key_write=1 row_format=dynamic comment= ' article table '



You can vote only if the user is restricted to the user ID and the subject ID of the poll.

same article?? It can only be cast once.

table?? OK??
ID
aid?? ID
mid with? ID
Addtime????

Select COUNT (*) from table where aid=? and mid=? = 1?? Is it possible to vote again????。

It is not possible to restrict by cookie or IP alone.
must use to SQL


But there's a performance problem to ask.

Which of the following two scenarios is good?

A. Positive/negative comments placed in the column of the article table

Each time, in addition to adding a separate form, at the same time in the article of praise/Bad comment field +1

B. Create a separate form to record the actions of positive/negative comments

One new record for each positive/negative review
Comment Table
ID (Automatic)
UID User ID
Tid article ID (topic ID)
Vote rated/Poor reviews (1/0)

Article tid=90
What's the difference?
Rating: SELECT COUNT (*) from ' comment ' where ' tid ' = ' all ' and ' vote ' = ' 1 '
Bad Rating: SELECT COUNT (*) from ' comment ' where ' tid ' = ' vote ' and ' = ' = ' 1 '




The place of hesitation:
Plan A, every time to go to +1....topic content is certainly more than comment data space, feeling will be more consumption?

But in topic, in the list of articles, select must be more resource-saving because only select topic is a single sheet, and you don't have to calculate how many of the comment tables are related to Tid.

Plan B, the topic operation will be less when the comment is not used, but to select ... It's like counting the count (*) every time. Would it be more resource-consuming? If 50,000 articles average 200 good/bad reviews per article, so comment already has 10 million data??? What if more? Or will the count (*) not be able to afford the millions of data? Because of the list of topics?

In this first not to discuss the cache problem, purely in these two SQL scheme which compares low consumption of resources a bit?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.