php 商家评分系统,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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值