I am currently coding a gambling system for a client, effectivly, the way the system works is as follows:
- Tickets are what we create
- Each ticket will get assigned a certain amount of numbers per ticket
- There are a total of 1,000,000 which are ordered randomly from 000,000 to 999,999
- These 1 million numbers get split into tickets the amount of numbers per ticket is defined by the admin.
Now the problem is at the moment we have an array of 1 million numbers sorted randomly, this is fine, but what would be the best way to insert this into a database?
We have two tables
tickets
- ID
- ticketUID
- prizeID
- addedDate
ticketNumbers
- ID
- ticketID
- number
At the moment when the user decides to add the tickets to the prize we loop through and create the total tickets which is determined by the total amount of numbers per ticket, e.g. 1 number per ticket = 1 million tickets, etc…
Now we loop through check the total numbers per ticket add how ever many from our number array then remove it from the original array so there are no duplicate numbers.
Now where the problem stems from is that this takes quite a lot of memory in this way and it causes the page to time out….
Is there another way someone can suggest to help overcome this problem?
P.S. I cannot provide source code, but this is essentially what we are doing, and what i really need is theory of other methods of how i could handle the insertion of all this data.
Thanks in advance
I’m not really into gambling, so not really sure in which way these tickets have anything to do with gambling.
That said, if you really need to create such an amount of data, there are a few options. You could for example move the ticket-creating away from the user. What I mean with that is whenever the user decides to ‘add the tickets to the prize’ you delegate this task to another process/thread and let the user move on. Then when the creation of the tickets is done, the process notifies the user somehow.