Hi i have a table for coupons in there i got lots of data's inserted already. if one user subscribe that table will be update and assign to that coupon to user.
ID coupon user created Instance
1 xxxx email@example.com 2016-06-15 1
2 xxxx firstname.lastname@example.org 2016-06-15 1
3 xxxx email@example.com 2016-06-15 1
4 xxxx firstname.lastname@example.org 2016-06-15 1
5 xxxx 0000-00-00 0
6 xxxx 0000-00-00 0
7 xxxx 0000-00-00 0
You can use a query like this. after execution you can test with mysqli_affected_rows how many rows are changed.
UPDATE yourTable SET `Instace` = 1 , `USER` = 'theEmail' , `created` = now() WHERE id = (SELECT id FROM yourTable WHERE Instance = 0 AND `USER` IS NULL LIMIT 1) AND 50 > (SELECT COUN(*) FROM yourTable WHERE `created` = NOW());