0

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

UPDATE slots SET time = NOW(), name = "John Doe"
WHERE hour=14 AND name=""
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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jorisb
0

Found the solution. Replace

BUT AT MOST 1 ROW

with

LIMIT 1

Thanks,

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.