PHP ranking code

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
mimic
Forum Newbie
Posts: 4
Joined: Thu Aug 01, 2013 3:49 am

PHP ranking code

Post by mimic »

Hi I am making a shopping site and wish to display some user ranks.

How can i rank each user for a certain field, and then insert the user's rank

into a corresponding field for each user? Ranking is detarmined based on the

amount($) of transaction made in the last 6 months and depend on the rank defferent commission fee will be applied.

Rank variation is

Premium(more than $600) commission fee is 5%
Gold($301-$600) commission fee is 9%
Silver($101-$300) commission fee is 11%
Bronze(0-$100) commission fee is 13%

Any help will be appreciate.

Thanks for your help.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP ranking code

Post by requinix »

You don't have to store the rank anywhere. All you need is the total transaction amount and that is simple enough with a SQL query.

Do the ranking in code.

Code: Select all

if total >= 600 {
    commission fee = 0.05
} else if total > 300 {
    commission fee = .09
} else if total > 100) {
    commission fee = .11
} else {
    commission fee = .13
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP ranking code

Post by Christopher »

You could make it data driven with something like this code. Then you could put the ranks into config data.

Code: Select all

$user_ranks = array(
        array(
            'amount' => 600,
            'fee' => 0.05,
            ),
        array(
            'amount' => 300,
            'fee' => 0.09,
            ),
        array(
            'amount' => 100,
            'fee' => 0.11,
            ),
        array(
            'amount' => 0,
            'fee' => 0.13,
            ),
    );
foreach ($user_ranks as $rank) {
    if ($total >= $rank['amount']) {
        $commission_fee = $rank['fee'];
        break;
    }
}
(#10850)
Post Reply