How to make a payout system

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

How to make a payout system

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do a simple join where id = userid and paid <> 'p'
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

uhh,cn you explain joins to me? im not really keen on it. i dont seem to understand the concept of it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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;
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,well i dont think i will understand that,ill just leave it simple like i have.thanks anyways.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

thanks. ill try to read up on it a little later. I will read when my skool ends because of my finals.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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.
Post Reply