Rating Of articles

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Rating Of articles

Post by kkonline »

I am working on an article manager, in which i want to use a rating rating (normal drop down select box with 1 to 5 value)

OPTION 1

To create this i have two options. Either i can use a rating table (a separate table in addition to the article,news,quote etc table) and keep all the ratings in it(for whole site)

Or

OPTION 2

I can have rating field in each (article,news,quotes etc. ) table and store the corresponding rating data in that.

I have different sections like quotes,articles,story,news etc. and the id is unique in a particular section. But if i use the 1st option then i will have to store article1,article2,news1,news2 etc... to identify the article and news. But in 2nd case i will just use id 1,2,3. ..


Please suggest which way is better/preferable keeping in mind that i would have enormous amount of db data in future.
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Post by vinoth »

According to my view storing the values along with the particular field is the best way Second Method
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

If you use the second method you'll need two columns - one to store the aggregate value of all the ratings, and another to store the number of ratings to date. So when someone rates an article as 4 stars for example you'd add 4 to the aggregate column and 1 to the number of ratings column. Then you just need to divide the aggregate by the number of ratings to get the current average. Of course that assumes you're using a basic "mean average" for the current score.
Post Reply