Hello have the following query:
SELECT code FROM tbl_codes WHERE used='0' ORDER BY RAND() LIMIT 2;
This will result in 2 codes with unique value (ex: code = 1 code = 2). After that I will update the table that those codes are used with following query:
UPDATE table_codes SET used='1', mail_at=NOW(), user='1' WHERE (code='1' OR code='2') AND used='0';
My question is how to prevent that another user get the same 1 or 2 codes of the first user? The 2 codes can only assigned to 1 user.
Users can get 2 tickets for an event. The 2 codes will be send by mail as barcode to scan at the event.
UPDATE table_codes
SET used = 1
, mail_at = NOW()
, user = 1
WHERE used = 0
ORDER
BY RAND()
LIMIT 2;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.