Reputation: 15
I'm looking for advice or idea about this situation. I have a Table session. Each session can have up to X guest.
SESSION
idSession
MaxGuest
I have another table TICKETS. When someone order X tickets for a SESSION I would like to make sure there is enough ticket available between the moment he ordered the tickets and the moment the system has recorded his order.
Example:
If I have many orders at the same time I may have this problem.
The only idea I see is to have a table to store current process order and check the qty available from the number of tickets already ordered and the number of ticket being ordered.
Does anyone has a better idea? I wonder if it's not too "heavy"? Any help would be appreciated.
Upvotes: 0
Views: 452
Reputation:
You need to use AJAX and PHP for this idea to work. Without AJAX, information could be retrieved from the server that is not recent. Orders can happen in seconds. I would do something like this:
init.php
if($watching){
echo 1;
} else {
echo 0;
}
You could set $watching
to retrieve information from your db and check if items are still available.
page.php
<script>
function isWatching() {
$.get('init.php', function(data){
if(data == 1) {
alert('You are watching a video');
} else if(data == 0) {
alert('You are not watching a video');
}
});
}
setTimeout(isWatching, 1000);
</script>
NOTE: I would not recommend setting the interval to one second.
Upvotes: 1