Link to home
Create AccountLog in
Avatar of level9wizard
level9wizardFlag for Canada

asked on

Delegating SQL updates to rows democratically

THE CHALLENGE
- Let's say I have 5 users (rows) in a table called Players.
- I may add or remove a Player in at any time.
- Each Player has a field 'Cards' to store dealt cards (just an integer of total received so far).
- At any random point/time in the day the dealer [dealer.php] may deal a card to a user.

Using PHP and/or MySQL How can I make sure that is it sequential? Such that user 1 gets a card, and then user 2, and then user 3 until all Players [rows] have got one, and then start back at Player one again.

THE PROBLEM
I/you can't simply fetch the rows from MySQL because it doesn't just happen once (like dealing 52 cards in one shot). Instead, there's really an infinite number of cards (or at least an unknown amount). Also, the dealer may send a card at any time and doesn't know who had one last, and since the rows of Players are dynamic the php function will need to account for this.

END GOAL
The end goal is to then 'weigh' certain players such that they will receive 2 cards in one round where others get only 1. I want to use a 'Weight' field for each player. By default all players have a weight of '1' and having a greater weight such as '3', means they recieve 2 more cards each round.
ASKER CERTIFIED SOLUTION
Avatar of loki23
loki23

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.