-2

I am creating a competition page and have a ticket table in mysql. Each ticket contains an availability column which is either '1' or '0' (true or false).

When the user adds a ticket to their basket I am setting the value to 0 so that other users cant attempt to buy that ticket while it is being purchased by someone else. I am wanting a timeout so that the value will essentially set back to 1 after x amount of time (let's say 10 minutes)

I get how to do all aspects except this timer. I have seen something about events but I am not sure how to use them.

Pseudocode for what I want

adding to basket
availability = 0

trigger timer event
after 10 mins

if purchased = 0
    availability = 1

(I am mainly controlling the site with PHP)

Braiam
  • 1
  • 11
  • 47
  • 78
robby11110
  • 27
  • 7
  • 4
    just a note, phpMyAdmin is your mySQL administration tool, no need to tag your question with it, in the end it isn't relevant when the community wants to provide you with answers :) – meewog Aug 07 '20 at 15:20
  • There is [How to set a timer in mysql](https://stackoverflow.com/questions/27018992/how-to-set-a-timer-in-mysql) – Scratte Aug 08 '20 at 17:18

1 Answers1

1

You'll probably find life easier if rethink your strategy. You will find that if you change your availability field to be a date you can change your strategy to this, and get the same net behaviour without the added complexity of the scheduled process to unlock;

  • Allow adding to basket if availability before now and not purchased.
  • Set availability to a date in the future that the ticket becomes available to purchase and purchased = 0.
  • When someone adds the ticket to their basket set the availability field to now + 10 mins (this will ensure that for the next 10 mins that ticket cannot be claimed but after 10 mins it will automatically be available without any extra processing).
tocsoft
  • 1,709
  • 16
  • 22
  • Wow I never thought of it like that. I might still have a play around with the timers for something else in my own time but this will definitely be my chosen method. My first question on stack overflow as well so I really appreciate this answer :) – robby11110 Aug 09 '20 at 21:15