Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:星级系统概念?_Php_Mysql_Database Design_Rating - Fatal编程技术网

PHP:星级系统概念?

PHP:星级系统概念?,php,mysql,database-design,rating,Php,Mysql,Database Design,Rating,我正在使用PHP/MYSQL/JQUERY 我有一个网站,其中有新闻部分。在新闻详情页面上,我想添加明星评级系统,允许用户对新闻故事进行评级。我正在使用这个jquery评级系统 现在,我没有得到什么将是数据库结构,然后我需要什么代码在PHP。我需要什么逻辑将适用于这一点,例如,如果有1000人投票支持这篇文章,一些人给予评分为2或3或1或5。然后我应该在哪里存储(db结构)这一切以及我将要计算的内容(在php代码中) 如果有人有任何文章显示了这个概念,请提供 请帮助,理解这个逻辑和概念 谢谢 下

我正在使用PHP/MYSQL/JQUERY

我有一个网站,其中有新闻部分。在新闻详情页面上,我想添加明星评级系统,允许用户对新闻故事进行评级。我正在使用这个jquery评级系统

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

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

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


谢谢

下面是一个非常简单的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;

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


明白了,哇,在这种情况下,我甚至不需要用PHP编写任何代码?这一切都将由mysql来处理,对吗?谢谢您需要一些php代码将数据插入到image_投票表中,仅此而已:)