I have an idea for a virtual stock market game. What I want to do is make each individual stock virtually 'physical', if that makes sense. In my market, users are able to create their own company and they will have 100,000 stocks. The stock price defers on many variables, including some random. My question is, how should I store these individual stocks? For example, lets say Company A currently owns all their stock, each at $120.00. Let's say Company B wants to buy 50,000 of their stocks. Ownership of the stocks has nothing to do with ownership of the company, it merely serves as a way to increase capital. I'm using MySQL as well as PHP. I was thinking of having a separate table called 'stocks', and it would be structured as such:

+--Company--+--Price--+--Last Price--+--Owner--+
|     A     |  120.00 |     110.00   |    B    |

And there would be 100,000 rows of this stock. Last price would be used to determine a percentage gain. In my head, this seems perfect. Realistically, the amount of rows that would be inserted into the database would consume massive amounts of data as well as performance. I'm looking for suggestions on how I should implement this feature in a minimized way.



You could, in theory, make a multi-dimensional array within PHP, and then JSON encode it and store it in a table with a structure like this:

Company|Current Stocks

The multi dimensional array could look like this:


Then just decode it in PHP whenever you need to access these values.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow