The Little Guy Posted May 15, 2009 Share Posted May 15, 2009 I am building a "Fake" bank, when a user signs up, he/she starts out with a $500,000 loan from the bank. He/she then can buy or sell stuff, and each transaction will be stored in a table in the database. I am wondering, will I get an accurate user balance if I use mysql SUM on ALL of the users transactions? SELECT SUM(`amount`) as loanSum FROM bank WHERE owner = '$this->owner' AND (type='l' OR type='d' OR type='w') type l = loan type d = deposit type w = withdrawal (this contains a negative value such as: -400) Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/ Share on other sites More sharing options...
.josh Posted May 16, 2009 Share Posted May 16, 2009 yes. also, instead of all of those OR's, you can do SELECT SUM(`amount`) as loanSum FROM bank WHERE owner = '$this->owner' AND type IN ('l','d','w') Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835080 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 What other types are there? Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835082 Share on other sites More sharing options...
.josh Posted May 16, 2009 Share Posted May 16, 2009 type r = rob lol. Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835086 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 That was a good one. Just noticed. Can you use $this->owner inline in the string like that? Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835087 Share on other sites More sharing options...
The Little Guy Posted May 16, 2009 Author Share Posted May 16, 2009 Just noticed. Can you use $this->owner inline in the string like that? Yes! I didn't think it would work either Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835094 Share on other sites More sharing options...
trq Posted May 16, 2009 Share Posted May 16, 2009 Complex variables should be surrounded by {} braces. SELECT SUM(`amount`) as loanSum FROM bank WHERE owner = {'$this->owner'} AND type IN ('l','d','w') Quote Link to comment https://forums.phpfreaks.com/topic/158318-a-bank/#findComment-835096 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.