I am designing a website that will provide vouchers (serial codes). All voucher codes generated and saved in a table like this and not generated online:
v_id voucher status (used?)
-------------------------------------------------------
1 abcdefgabcdefg1 0
2 abcdefgabcdefg2 0
3 abcdefgabcdefg3 0
4 abcdefgabcdefg4 0
I should display unused (status:0) voucher to end user after successful payment but I am not sure how can I do this because this site may have high traffic so more than one people may visit site in same milisecond of time, so for example I can not just use:
SELECT * FROM table WHERE status=0 LIMIT 0,1;
and then UPDATE it:
UPDATE table SET status=1 WHERE v_id=....
because two people may visit in same time so we provide same serial code in SELECT before we UPDATE.
what would be best way to ensure I display unique serial code?
Asked by max
(1 rep)
Dec 9, 2016, 02:14 PM
Last activity: Feb 12, 2025, 12:07 PM
Last activity: Feb 12, 2025, 12:07 PM