I need to do something similar to reputation/awards on stack overflow.
Lets say I want to give out an award when a users rep exceeds 500. (award number 7 for example)
But I only want the award to be given once, so if the rep decreased and then increase again, they wouldn’t get two awards.
INSERT INTO awards (number, username, date) SELECT 7, username, NOW() FROM users WHERE rep>500;
And then have primary key username, number
Trigger:
CREATE TRIGGER `rewards` BEFORE INSERT ON `awards`
FOR EACH ROW BEGIN
UPDATE users SET points=points+1 WHERE username=NEW.username AND NEW.number=7;
END
but i get this error:
Simply create a trigger on the table awards
http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html