shibbs — 2012-10-01T19:45:05-04:00 — #1
So I have the following problem.
The problem concerns 3 columns: upvote, downvote, score where
score is created by taking upvote/downvote
I now want to create a trigger which will update my
score column after either the
upvote or the
downvote where updated.
I looked at a bunch of stuff online and tried several things but never got it to work.
Including something like this.
create trigger trigger1 after update of (up or down) on table1 for score
set new.score =concat(up/down);
I've never created triggers before so this is completely new for me.
guelphdad — 2012-10-01T20:06:42-04:00 — #2
score doesn't belong as a column in the table, it can be calculated on the fly from the other two columns.
shibbs — 2012-10-01T20:52:02-04:00 — #3
I agree that it should be like that in most cases, however if I create the score in my php file I have a problem with displaying the content once I order the table.
If I had the extra column this problem wouldn't exist. I know this might not be the best way but it is definitely a way that will work.
r937 — 2012-10-01T21:23:43-04:00 — #4
no you don't --
ORDER BY upvote/downvote
shibbs — 2012-10-01T21:31:59-04:00 — #5
Yes that works, but there are formulas which are better suited for a rating system so that 2up 1down dont have the same effect as 200up and 100down.
Thus I think if I can create a column with that formula I wont run into any problems with urlencoding a plus sign and stuff like that.
guelphdad — 2012-10-01T23:09:27-04:00 — #6
right and you've now just created a whole new scenario from your original haven't you?
shibbs — 2012-10-01T23:11:04-04:00 — #7
Ok, sorry about that,
I wanted to make up a simple scenario to make it as clear as possible.
I was not expecting people to tell me that I should use alternative ways.