Solved

Delegating SQL updates to rows democratically

Posted on 2008-06-12
2
178 Views
Last Modified: 2008-06-17
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.
0
Comment
Question by:level9wizard
2 Comments
 
LVL 2

Accepted Solution

by:
loki23 earned 250 total points
ID: 21771978
how about adding a boolean field to each row to act as a flag that the script can check to see who was the last person dealt a card? When a person gets a card, set the flag to true. Next time around, check the database for the player with that flag set to true, change it to false, and then deal a card to the next person and set their flag to true.

May require a couple DB calls, so it might be best to set up a DB Procedure.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 21772996
One way to make the dealing sequential is to timestamp the action, then use the oldest timestamp to receive the next card.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now