3

我正在使用 PHP/MYSQL/JQUERY。

我有一个有新闻部分的网站。在新闻详细信息页面上,我想添加星级评分系统,允许用户对新闻故事进行评分。我正在使用这个 jquery 评级系统http://www.fyneworks.com/jquery/star-rating/

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

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

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

谢谢!

4

2 回答 2

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;
于 2010-12-23T15:14:05.850 回答
1

ColorBox 的制造商制作了一个 jQuery/PHP 评级系统,您可以使用它,称为 ColorRating。ColorBox 是一个很棒的程序,所以我认为 ColorRating 也是如此。我会检查一下,因为它可能会为您节省很多麻烦:

http://colorpowered.com/colorrating/

于 2010-12-23T15:51:00.583 回答