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
INSERT INTO tickeNumbers (ID, tickedtID) VALUES ('$tid', $currnum), ('$tid', $currnum), ('$tid', $currnum), (...)doesn't seem terribly inefficient.