Page 1 of 1

How to make a payout system

Posted: Wed May 31, 2006 3:26 pm
by a94060
Hi,i was wondering what would be the best way to store how much a user is owed. BAsically, i need to make an admin panel that will show all the users and when they select one,their total payout will be showed up on the screen (i have the user table done). The problem i have is how would i select all the recoreds with the users id,add up the prices,and then,when the admin selects Payed/Payout or whatever,that all the entries previously selected,will get a "p" or something in the paid column. This way,the next time the admin views the payout for the person,it will tell me that there is nothing to be owed to that user?

Posted: Mon Jun 05, 2006 10:33 am
by RobertGonzalez
Can you add an account balance to the user record and subtract from/add to that when they are paid out or in debt?

Posted: Mon Jun 05, 2006 10:51 am
by Todd_Z
I would make a transactions table, listing all the transactions that go to a user, from a user. That way you can use simple SQL statements to calculate the balance on their account. You could have a datetime field "paid" - when its null, it hasn't been paid, when its a valid stamp, it has been paid.

Posted: Mon Jun 05, 2006 12:06 pm
by a94060
well,what i did was make 3 tables. one store all of the offers,their type and their value.once someone completed them,it would be moved to the poffer(pending) table. if the admin verified that it was complete,it would move to the coffers(completed) table. in that table,i added a new field called paid. If the offer was paid,it would have a "p" in the column. I would then select all the values for the user that dont have a "p." Now,i guess my question is:How do i select all entries which are of a specific person which dont have a p in that column.

Posted: Mon Jun 05, 2006 12:54 pm
by RobertGonzalez
Do a simple join where id = userid and paid <> 'p'

Posted: Mon Jun 05, 2006 2:43 pm
by a94060
uhh,cn you explain joins to me? im not really keen on it. i dont seem to understand the concept of it.

Posted: Mon Jun 05, 2006 2:58 pm
by RobertGonzalez
OK, say you have a table of users with the following fields:
1. user_id
2. user_name
3. user_password

And you have another one with offer information:
1. user_id
2. user_offer
3. user_is_closed

You can select from these two tables using a join...

Code: Select all

SELECT u.user_name, o.user_offer 
FROM user_table u 
INNER JOIN offers_table o 
ON o.user_id = u.user_id 
WHERE o.user_is_closed <> 1;

Posted: Mon Jun 05, 2006 3:06 pm
by a94060
ok,well i dont think i will understand that,ill just leave it simple like i have.thanks anyways.

Posted: Mon Jun 05, 2006 3:17 pm
by RobertGonzalez
I'll tell you this much, my code really opened up the day I learned how to write effective queries on normalized table data. I would recommend that you spend a little time and learn how to write complex queries because they have seriously minimized my code and coding time. Just a suggestion.

Posted: Mon Jun 05, 2006 4:02 pm
by a94060
thanks. ill try to read up on it a little later. I will read when my skool ends because of my finals.

Posted: Tue Jun 06, 2006 11:51 am
by Todd_Z
thats a really good point, there are ways to manipulate data in sql queries that it could take an hour or two to manipulate arrays and whatnot in the same way with php.

Posted: Tue Jun 06, 2006 12:04 pm
by a94060
yea,ill try to learn how to do this and i will read the manual over the summer. i think that the biggest problems that i have is with the concatation in SQL queries and in echo staments and other places.