tags:

views:

27

answers:

2

Every programmer here knows about ratings like that:
Rating system

The problem is that I don't know how to make my SQL structure for that.

I think I can add up and down field in article table in MySQL, but this does not allow multi voting.

Could you please tell me how to make it?
Do I have to create a new table?

+2  A: 

The easiest way is to simply store the vote counter per article.
When an article gets voted up, increase the counter. Voting down - decrease the counter.

If you need to keep track about which user voted up/down (and avoid multiple votes), you need to define an intersection table between users and articles.

It could look like this:

article_votes
--------------
user_id
article_id
vote

where vote can be either +1 or -1.

If you need the points of an article, you get it by

SELECT SUM( vote )
FROM article_votes
WHERE article_id = <your_article_id> 
Peter Lang
thats is he same i think and this is the first time know the sum()
moustafa
+2  A: 

You may get some ideas out of how stackoverflow does it:

BalusC