?
Solved

Delegating SQL updates to rows democratically

Posted on 2008-06-12
2
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
loki23 earned 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

770 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