Jump to content

Recommended Posts

Ok. I'm trying to figure out the best/most optimized way to design my tables. I have multiple purchases go through my website. For each purchase, a percentage is given to different places (the user, company profit, and a bonus pool - more needs to be able to be added at any time). I want to keep track of all of this, be able to trace every transaction, pull up transactions at will and know the balance of each account (company profit and bonus pool will only have 1 account, but there could be 50-10,000 users).

 

One way I've thought of is to create an "account type" for each user. IE:

 

Table: Type_Of_Accounts (this table holds the option for different payable accounts)

 

id (primary key - auto increment)

name

 

Examples:

 

1 / user

2 / company_profit

3 / bonus_pool

 

Table: Transaction_Log (this table holds all transaction information.)

 

id (primary key - auto increment)

type_of_account_id (matches Type_Of_Accounts)

account_id (if it's a user account, this field will hold the user id. if not, it will be set to 0).

amount

time

 

Examples:

 

1 / 1 (user account) / 40 (user_id) / 59.99 / <time>

2 / 3 (bonus pool) / / 19.99 / <time>

 

Table: balances (this would just update each time a transaction went through, this way I don't have to calculate it on the fly each time).

 

id

type_of_account_id

account_id

balance

 

Examples: (using data from above)

 

1 / 1 / 40 / 59.99

2 / 2 / / 19.99

 

Here are some example queries:

 

Get a users transaction log: select * from Transaction_Log where type_of_account_id='1' AND account_id='x'

 

Get the transaction log for the bonus pool: select * from Transaction_Log where type_of_account_id='3' and account_id='0'

 

To get the balance of the companies profit you could do: select balance from balances WHERE type_of_account_id='2' AND account_id='0'

 

-----------------

 

What are your thoughts on this, and do you have a better way of designing this? I want it to be optimized/designed the best way possible.

Link to comment
https://forums.phpfreaks.com/topic/237397-database-design/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.