Reputation: 2652
Ok, what I have right now is this:
START TRANSACTION;
SELECT redeemTicketChances FROM userRedeemChances WHERE userId='917' FOR UPDATE;
UPDATE userRedeemChances SET `redeemTicketChances` = redeemTicketChances - 1;
COMMIT;
What I want to know is if redeemTicketChances is 0. If it is 0 I do not want to subtract 1 from it. I also want it to return back to php whether or not it successfully subtracted 1 or if redeemTicketChances is already 0.
I am not great at advanced sql like this so I'm not really sure what to do from here.
Upvotes: 0
Views: 965
Reputation: 160883
UPDATE userRedeemChances SET `redeemTicketChances` = redeemTicketChances - 1
WHERE redeemTicketChances > 0 AND userId='917'
Upvotes: 4