"Claim a slot" database design

Thread Solved

Join Date: Oct 2009
Posts: 2
Reputation: jorisb is an unknown quantity at this point 
Solved Threads: 0
jorisb jorisb is offline Offline
Newbie Poster

"Claim a slot" database design

 
0
  #1
Oct 18th, 2009
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

  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; 34 Days Ago at 5:58 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: jorisb is an unknown quantity at this point 
Solved Threads: 0
jorisb jorisb is offline Offline
Newbie Poster
 
0
  #2
Oct 19th, 2009
Found the solution. Replace

Originally Posted by jorisb View Post
BUT AT MOST 1 ROW
with

LIMIT 1

Thanks,
Reply With Quote Quick reply to this message  
Reply

Tags
design, update

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC