I have created a simple stock trading simulation website. Users can sign up and buy/sell stocks. Now, I’ve come to a problem. When a use buys a stock (can be more than one share), how do I put this into a database?
This is a bit of a challenge because each user can buy any stock that exists and they can buy any quantity.
Here’s an example of what I’m trying to store into a db:
Stocks owned by username1261817
Symbol: Quantity
goog: 3
yhoo: 8
aapl: 3
etc…
You might have to design your table like how a shopping cart would do. Include fields – userid (comes from user table), stock symbol, quantity, stock price at the time of purchase, date purchased. This will help you generate the necessary reports like total stocks of one type, total stocks owned by a user etc.