943,982 Members | Top Members by Rank

Ad:
Oct 18th, 2009
0

"Claim a slot" database design

Expand Post »
I'm developing a web page for a friend that allows participants of a sports event to "claim" a slot in a 24 hour tennis marathon. The marathon has room for 24 x 4 participants.

My idea was to have a table with the columns "hour" [0-23], "time" and "name", and pre-fill that table with 4 rows for each hour that have empty time and names columns.

Then, when someone fills in the form stating his name and the hour he wants to play, I'd update the table using something like

sql Syntax (Toggle Plain Text)
  1. UPDATE slots SET TIME = NOW(), name = "John Doe"
  2. WHERE HOUR=14 AND name=""
  3. BUT AT MOST 1 ROW

and then I'd check PHP's mysql_affected_rows() to see if the slot was claimed successfully. Because if 5 people are trying to enroll for the same hour simultaneously, one of the attempts will have to fail.

I can't find a way to do this. So, my design is probably incorrect? Any suggestions how to tackle this? Thanks

Joris
Last edited by peter_budo; Oct 20th, 2009 at 5:58 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jorisb is offline Offline
2 posts
since Oct 2009
Oct 19th, 2009
0
Re: "Claim a slot" database design
Found the solution. Replace

Click to Expand / Collapse  Quote originally posted by jorisb ...
BUT AT MOST 1 ROW
with

LIMIT 1

Thanks,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jorisb is offline Offline
2 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Database Design Forum Timeline: mysql to sqlite
Next Thread in Database Design Forum Timeline: Database HELP....Logical and Conceptual Design





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC