简体   繁体   English

mySQL数据库-存储多标准评级

[英]mySQL Database - Storing Multi-Criteria Ratings

I've been doing a lot of searching and reading about rating systems, but couldn't find a solution to what I'm trying to achieve... 我一直在进行很多搜索和阅读有关评级系统的事情,但是找不到解决方案来解决我要实现的目标...

I have a website where users, once logged in, can submit a product. 我有一个网站,用户登录后即可提交产品。 Now I want other users to be able to rate those products according to 3 different criteria. 现在,我希望其他用户能够根据3个不同的标准对这些产品进行评分。 I'm using php and mySQL databases to store all of the information which is working great, I'm just not sure how to incorporate the ratings now. 我正在使用php和mySQL数据库存储所有运行良好的信息,但我不确定现在如何合并评级。

At the moment I have a PRODUCTS database, which holds various tables according to their category. 目前,我有一个PRODUCTS数据库,该数据库根据其类别保存各种表格。 Here's an example of a table: 这是一个表格示例:

TOASTERS
---
ID (auto-incrementing)
Brand
Set
Number
Name
Edition
Image (stores the location of the image the user uploads)

Any user can then rate that row of the table out of 10 for 3 criteria (Quality, Price, Aesthetic). 然后,任何用户都可以为3个条件(质量,价格,审美)在10分之内对表格的该行进行评分。 The user average of each criteria is displayed on each product page but I would like to store each of the user's individual ratings so that I can show a short history of their ratings on their profile page. 每个标准的用户平均值显示在每个产品页面上,但是我想存储每个用户的个人评分,以便我可以在其个人资料页面上显示其评分的简短历史记录。 Or have a live feed of the latest user ratings on the homepage. 或在首页上实时获取最新的用户评分。

What I'm trying to do is quite a lot like awwwwards.com . 我想做的很像awwwwards.com (See bottom-right of page to see the livefeed I'm talking about) (请参阅页面右下角以查看我正在谈论的实时供稿)

Thanks in advance! 提前致谢!

I think you should use single PRODUCTS table or at least create PRODUCTS table and emulate inheritance between it and category tables. 我认为您应该使用单个PRODUCTS表,或者至少创建PRODUCTS表并模拟它与类别表之间的继承。

Having a table for each category can give some advantages if each category has some specific properties, but it can lead to neccesity of writing separate code to work with each table. 如果每个类别都有一些特定的属性,则为每个类别都有一个表可能会带来一些好处,但是,这可能导致需要编写单独的代码来处理每个表的必要性。 Alternatively you can use two tables to store all custom properties 'vertically': PROPERTIES(propertyID,PropertyName) , PROPVALUES(productID,propertyID,PropertyValue) . 或者,您可以使用两个表“垂直”存储所有自定义属性: PROPERTIES(propertyID,PropertyName)PROPVALUES(productID,propertyID,PropertyValue)

If you choose to have multiple tables and emulate inheritance, it can be achieved like this: 如果选择具有多个表并模拟继承,则可以这样实现:

PRODUCTS
---
ID (auto-incrementing)
Brand
Set
Number
Name
Edition
Image
VoteCount    <+
SumQuality    +-updated by trigger
SumPrice      |
SumAesthetic <+

TOASTERS
---
productID (PK and FK to PRODUCTS)
(toaster specific fields go here, if any)

Than you will be able to create table VOTES, referencing table PRODUCTS 比您将能够创建表VOTES,引用表PRODUCTS

VOTES
---
productID (FK to PRODUCTS)
userID (FK to USERS)
Quality    
Price     
Aesthetic
VoteDateTime

If it is true that overall product rating is queried much more often than voting history, as an optimization you can add fields VoteCount, AvgQuality, AvgPrice, AvgAesthetic to PRODUCTS table, as srdjans already supposed. 如果这是真的,商品整体评价中查询更往往比投票历史,你可以添加字段VoteCount,AvgQuality,AvgPrice,AvgAesthetic到产品表,作为优化srdjans已经设想。 You can update this extra fields by trigger on table VOTES or manually in PHP code. 您可以通过在表VOTES上触发或在PHP代码中手动更新此额外字段。

Create separate table for storing user individual ratings (primary key, user id, product id and ratings). 创建单独的表来存储用户的个人评分(主键,用户ID,产品ID和评分)。 Create additional fields in "products" to store averages. 在“产品”中创建其他字段以存储平均值。 Every time some user rates some product, you insert record in "ratings" table, then calculate averages again for given product, and update rows in products. 每次用户对某种产品进行评分时,您都将记录插入“评分”表中,然后再次计算给定产品的平均值,并更新产品中的行。 Doing this you will have easy access to ratings, and also, you can analyse user individual ratings. 这样一来,您将可以轻松访问评分,还可以分析用户的个人评分。

Ps - You may also wish to store how many users rated some product. 附言:您可能还希望存储多少用户对某些产品进行了评分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM