php - Automatic Mysql updates -
is possible have mysql automatically update field in table once number reached?
i have table called badges
, has these fields
id,name,image,level, percent
can make if percent field gets number (for example 50) , level field updated 2 .
i think trigger ?
you can several things.
in syntax
you can write in syntax, allthough value not changed in table else displayed. this
select id, name, image, case when percent > 50 2 else level end level, percent from....
in trigger
after each insert have count value , update accordingly. maybe this
delimiter $$ drop trigger if exists databasename.badges_aupd$$ use databasename$$ create trigger `badges_aupd` after update on `badges` each row // added line andreas wederbrands answer correct way set new.level := case when percent < 50 0 when percent < 75 1 else 2; $$ delimiter ;
in stored procedures
you schedule event executes stored procedure. wont work if need value changed once reaches 50.
create procedure `updatelevel` () begin update badges set level=2 precentage > 50; end
Comments
Post a Comment