PHP:星评系统概念? [英] PHP: Star rating system concept?

查看:102
本文介绍了PHP:星评系统概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP / MYSQL / JQUERY。



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



现在,我没有得到什么将是数据库结构,然后我需要在PHP中编码。我需要为此应用什么逻辑,就像1000个人投票赞成的文章,一些给定的评级为2或3或1或5.然后我应该存储(db结构)这一切,我会计算(在php code)。



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



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



谢谢!

解决方案

这里有一个非常简单的mysql示例: / p>

  drop table if exists image; 
创建表格图像

image_id int unsigned not null auto_increment主键,
caption varchar(255)not null,
num_votes int unsigned not null默认值0,
total_score int unsigned not null default 0,
rating decimal(8,2)not null默认值0

engine = innodb;

drop table if exists image_vote;
创建表image_vote

image_id int unsigned not null,
user_id int unsigned not null,
score tinyint unsigned not null默认值0,
主键(image_id,user_id)

engine = innodb;

分隔符#

在每一行插入image_vote
后创建触发器image_vote_after_ins_trig
begin
更新映像集
num_votes = num_votes + 1,
total_score = total_score + new.score,
rating = total_score / num_votes
其中
image_id = new.image_id;
end#

delimiter;

插入图像(标题)值('image 1'),('image 2'),('image 3');

insert into image_vote(image_id,user_id,score)value
(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_vote;


I am using PHP/MYSQL/JQUERY.

I have a site which have news section. On news details page, I want to add star rating system which will allow user to rate the news story. I am using this jquery rating system http://www.fyneworks.com/jquery/star-rating/

Now, I am not getting what will be the database structure and then what I need to code in PHP. I need what logic will be applied for this, like if 1000 people voted for the article, some given rating as 2 or 3 or1 or 5. Then Where I should be storing (db structure) this all and what I'll calculate (in php code).

If someone has any article which shows this concept please provide.

Please help, to understand the logic and concept of this.

Thanks!

解决方案

here's a very simple mysql example:

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;

这篇关于PHP:星评系统概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆