Jump to content

Recommended Posts

I have been thinking of a game, and I was wondering if I were to have a bank, what would be the best way to store players in/out transactions. what kind of table structure would you do for something like that?

 

Lets say I were to transfer money to you, how would that transaction look?

 

- Would I insert 2 records into the table, one for me and one for you?

- Would I insert one record into the table and me and you share that record?

- Would you do something different, What?

Link to comment
https://forums.phpfreaks.com/topic/239144-cash-transaction-table/
Share on other sites

I have been thinking of a game, and I was wondering if I were to have a bank, what would be the best way to store players in/out transactions. what kind of table structure would you do for something like that?

 

Lets say I were to transfer money to you, how would that transaction look?

 

- Would I insert 2 records into the table, one for me and one for you?

- Would I insert one record into the table and me and you share that record?

- Would you do something different, What?

 

I would have two tables. Account_Balances (account_ID, account_Balance, timestamp) && Transaction_Records (payer, payee, amount, timestamp)

 

Then I would have three records... two updates and one insert all wrapped in a transaction to maintain the acid transaction.

 

"update Account_Balances set account_Balance=account_Balance-{$amount} where account_ID='{$transferee}';";

"update Account_Balances set account_Balance=account_Balance+{$amount} where account_ID='{$receiver}';";

"insert into Transaction_Records (payer, payee, amount) values ('{$transferee}','{$receiver}',{$amount});";

 

This assumes both accounts are at the same bank, of course.  And this design is super simple meant to address your base question... I'm sure with more time and energy I could brainstorm a whole bank, but I don't have the time or the energy...  :D

- Would I insert 2 records into the table, one for me and one for you?

 

Yes. It would be a debit (-) amount for the source account and a deposit (+) amount for the destination account.

 

@jtm62, having a second table that duplicates the balance from the account table is redundant information and is not necessary (do you keep track of your checking account by keeping track of the deposits/debits in one place and keeping track of the balance in another place?)

- Would I insert 2 records into the table, one for me and one for you?

 

Yes. It would be debit (-) amount for the source account and a deposit (+) amount for the destination account.

 

@jtm62, having a second table that duplicates the balance from the account table is redundant information and is not necessary (do you keep track of your checking account by keeping track of the deposits/debits in one place and keeping track of the balance in another place?)

 

I'm not duplicating anything.  I'm recording the amount, the payee, and the payer in the second table.  Personally, I want some way to know who paid who, and who received what from who... and I want a separate table to do that.  I don't feel it appropriate to record the second account id in my account balance table when making a transaction.

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.