Solved

Delegating SQL updates to rows democratically

Posted on 2008-06-12
2
176 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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

772 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

10 Experts available now in Live!

Get 1:1 Help Now