« first day (1820 days earlier)      last day (3125 days later) » 

11:00 PM
Morning's
 
And even if he's using an update clause, that still could cause a duplicate entry error.
 
Anonymous
INSERT INTO votes (user, post, vote) VALUES ("0003", 1, -1) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
 
Anonymous
@LGL It is working for me.
 
Anonymous
I forgot what your problem was, or I have lost my sanity again.
 
I've never seen an UPDATE vote = VALUES(vote) clause.
 
LGL
11:02 PM
@samayo yes cause thats only 1 vote.
 
Anonymous
it updates the post @LGL
 
LGL
One second let me try it
 
Anonymous
yeah, it's working :)
 
Anonymous
you need coffee.
 
LGL
Do you want me to do a Skype Screen sharing? its not
 
Anonymous
11:08 PM
INSERT INTO votes (user, post, vote) VALUES ("0005", 3, 7) ON DUPLICATE KEY UPDATE vote = VALUES(vote)
 
Anonymous
what do you get when you ran that?
 
LGL
-1
 
Anonymous
maybe you need to run this again ALTER TABLE votes ADD UNIQUE KEY vote (vote);
 
LGL
One second
 
Anonymous
It also makes 0 sense that when a duplicate vote is detected, you are only updating that vote field. ON DUPLICATE KEY UPDATE vote = VALUES(vote) what about the others?
 
Anonymous
@LGL you are missing the point of "ON duplicate update x" . You are telling mysql, "if users new vote number is already found in field x, then do nothing".
 
LGL
Right here this is after I run your code sqlfiddle.com/#!9/6bc1db/1 ALTER TABLE votes ADD UNIQUE KEY vote (vote);
total should be 2
 
is there any verb used to express "to make something contiguous"
 
Anonymous
infect zombiefy :)
 
Anonymous
@LGL what are you saying? the vote should be 2?
 
LGL
11:22 PM
Yes USER3 vote 1 and USER1 vote 1 on post 1
 
@samayo contiguous means touching or adjacent to. Actually, nevermind :)
 
LGL
Now when you get result of post 1 it should be 2
 
Anonymous
@LGL listen carefully.
 
Anonymous
INSERT INTO votes (user, post, vote) VALUES ("USER1", 1, 1) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
INSERT INTO votes (user, post, vote) VALUES ("USER3", 1, 1) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
INSERT INTO votes (user, post, vote) VALUES ("USER1", 2, 1) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
 
Anonymous
that does not make any sense.
 
Anonymous
11:26 PM
that is the whole point.
 
Anonymous
> if vote is duplicate, update vote ????
 
LGL
Yes
 
Anonymous
so, if vote is 1 then update it to 1.
 
LGL
no
 
Anonymous
Yes, because you are using ON DUPLICATE.
 
Anonymous
11:28 PM
You are not updating anything else.
 
Anonymous
basically, it does nothing.
 
LGL
exactly if user already voted 1 it should be 1 and if they change to -1 it should change to -1
But they can only vote once on each post.
 
Anonymous
so, you should check if USER is duplicate, not the vote.
 
Anonymous
on duplicate key update user = values(vote)
 
Anonymous
also for that work, user should be unique key.
 
LGL
11:32 PM
This is what happen
ON DUPLICATE KEY UPDATE user = VALUES(vote)
 
Anonymous
I thought you mean "they can only vote once" as opposed to "they can only vote once on each post"
 
LGL
Yeah
and if I do
ON DUPLICATE KEY UPDATE vote = VALUES(vote)
everything is correct except is not adding to 1 is adding extra row with -1
 
Anonymous
in that case, the duplicate should be post since you are checking first if post is same as before.
 
Anonymous
it should not be the vote.
 
LGL
K done post is the unique now.
Good now is updating
 
Anonymous
11:39 PM
So what is remaining now?
 
LGL
Oh wow,
I remember doing this but I think i made vote and post unique at same time.
but now is working
 
Anonymous
yeah, if you made the id unique it will skip before checking if post is duplicate.
 
LGL
Oh never mind the issue now it will be the user
another user can't vote
 
Anonymous
what do you mean, can't vote?
 
LGL
not if USER2 try to vote it won't get inserted.
Let me update SQLFiddle so you can see
See second user vote won't count sqlfiddle.com/#!9/446bec/1
or get inserted when i check in MySQL Workbench
 
Anonymous
11:46 PM
ah, ok.. so it is checking if post is duplicate, but not checking if user is duplicate.
 
LGL
yes
 
Anonymous
It is working, not just the way you want it
 
LGL
yep
cause other users should allowed to vote too :/
right?
 
Anonymous
yeah,
 
LGL
should I open a question?
I already wrote it.
 
11:52 PM
@LGL is this what you're after?
 
LGL
nope I'm after total of votes
 
Anonymous
that is what you are looking for actually.
 
LGL
I am?
 
Anonymous
INSERT INTO votes (user, post, vote) VALUES ("USER1", 2, 1) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
INSERT INTO votes (user, post, vote) VALUES ("USER1", 2, 0) ON DUPLICATE KEY UPDATE vote = VALUES(vote);
 
Anonymous
Since user and post are the same, the latter statement is updating the first like you expected it.
 
LGL
11:56 PM
shouldn't that be 1? sqlfiddle.com/#!9/041cf/1
 
why would it be 1?
 
Anonymous
It was 1. But it got updated, because user {USER1} changed his vote on the same post {2}.
 
LGL
Oh yes actually your right
 
Anonymous
I guess, you only want, upvote/downvote. like 1/-1 that is why you are confused.
 
LGL
Yes
user 2 can't vote
 

« first day (1820 days earlier)      last day (3125 days later) »