You are here: Re: MySQL is making me nuts! « PHP Programming Language « IT news, forums, messages
Re: MySQL is making me nuts!

Posted by smorrey on 11/13/44 11:30

Yes there is a house take, but there is also a percieved value here as
well.
The easiest way to understand what I am doing would be to consider it
like a currency conversion system or a market making system (in reality
this is for a role playing game with multiple regional currencies but I
think you catch my drift here.

In this instance we have USER 1 who is converting Gold to Clamshells
because USER 2 would like to be paid in ClamShells.
The transaction would look something like this.

assuming status is one of 3 values, proposed, accepted or rejected.

INSERT INTO transactions from_user, from_amount, from_cur, to_user,
to_amount,to_cur, fee, status

And actually is more like

INSERT INTO tranactions '1', '100','gold','2','900','clamshells','100',
'proposed'

Since a user can have "accounts" in anything tradeable in game which
amounts to over 200 regional currencies, I made a decision to not have
a "balance" table which seemed to be very exploitable.

On the other hand I never considered, updating the balance table on
each transaction for each currency type involved, and will have to look
closer at it.

In the final analysis, the only purpose for doing this on the website,
is to give weary travelers a place buy and sell thier wares w/o using
an auction channel or a forum that could get crowded like in EQ.

Anyways, thanks for the advice, I'll look into it and see how it works
out.

NC wrote:
> smorrey@gmail.com wrote:
> >
> > I'm trying to create a simple transaction handling system where users
> > pay eachother via points of a sort.
> > I have a table where each transaction is stored, in a single row.
> > It looks like this
> >
> > transid,from_user,from_amount,to_user,to_amount
>
> Why do you have from_amount and to_amount? Aren't they supposed
> to be equal? Or is there a "house take" of some kind?
>
> > Given the above, I just want a simple single SQL statement that can
> > return a full balance.
>
> Bad idea. If you want a transaction system, create a transaction
> system. You need to add a `balance` column to the table where
> user data is stored. Both the `users` table and `transactions`
> table must be InnoDB. Then you can actually do transaction
> processing:
>
> BEGIN;
> INSERT INTO `transactions`
> SET from_user = [from_user],
> from_amount = [from_amount],
> to_user = [to_user],
> to_amount = [to_amount];
> UPDATE `users`
> SET `balance` = `balance` - [from_amount]
> WHERE `id` = [from_user];
> UPDATE `users`
> SET `balance` = `balance` + [to_amount]
> WHERE `id` = [to_user];
> COMMIT;
>
> This way, balance is readily available as a single number;
> there's no need to query records from the beginning of the
> universe to look up balances...
>
> Cheers,
> NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация