PHP。星级评定系统概念?[关闭]

问题描述 投票:3回答:3

我使用的是PHPMYSQLJQUERY。

我有一个网站,其中有新闻部分。在新闻详情页,我想添加星级评价系统,这将允许用户对新闻故事的评价。我使用的是这个jquery评分系统 http:/www.fyneworks.comjquerystar-rating

现在,我没有得到什么将是数据库结构,然后我需要在PHP中编码。我需要应用什么逻辑,比如说如果有1000人投票给这篇文章,有些人给出的评分是2或3或1或5,那么我应该在哪里存储(数据库结构)这一切和我将计算什么(在php代码中)。然后,我应该在哪里存储(db结构)这一切,我将计算(在php代码)。

如果有人有任何文章显示这个概念,请提供。

请帮助,理解这个逻辑和概念。

谢谢!我是用PHPMYSQLJ的。

php mysql database-design rating
3个回答
3
投票

这里有一个非常简单的mysql例子。

drop table if exists image;
create table image
(
image_id int unsigned not null auto_increment primary key,
caption varchar(255) not null,
num_votes int unsigned not null default 0,
total_score int unsigned not null default 0,
rating decimal(8,2) not null default 0
)
engine = innodb;

drop table if exists image_vote;
create table image_vote
(
image_id int unsigned not null,
user_id int unsigned not null,
score tinyint unsigned not null default 0,
primary key (image_id, user_id)
)
engine=innodb;

delimiter #

create trigger image_vote_after_ins_trig after insert on image_vote
for each row
begin
 update image set 
    num_votes = num_votes + 1,
    total_score = total_score + new.score,
    rating = total_score / num_votes  
 where 
    image_id = new.image_id;
end#

delimiter ;

insert into image (caption) values ('image 1'),('image 2'), ('image 3');

insert into image_vote (image_id, user_id, score) values
(1,1,5),(1,2,4),(1,3,3),(1,4,2),(1,5,1),
(2,1,2),(2,2,1),(2,3,4),
(3,1,4),(3,5,2);

select * from image;
select * from image_vote;

1
投票

ColorBox的制作者做了一个jQueryPHP评分系统,你可以使用这个系统,叫做ColorRating。ColorBox是一个 巨大 程序,所以我认为ColorRating也是如此。我想看看它,因为它可能会给你省去很多麻烦。

http: /colorpowered.comcolorrating

© www.soinside.com 2019 - 2024. All rights reserved.