Page 1 of 1

PHP ranking code

Posted: Fri Aug 16, 2013 12:17 pm
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.

Re: PHP ranking code

Posted: Fri Aug 16, 2013 12:21 pm
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
}

Re: PHP ranking code

Posted: Fri Aug 16, 2013 2:45 pm
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;
    }
}