Jump to content

Can't get the sorting right.


Ninjakreborn

Recommended Posts

I have a list of players like this:

 

Rich Franklin - 19

Erick Silva - B

Jake Ellenberger - B

Joe Lauzon - F

Travis Browne - 9

Rory MacDonald - 0

Alexander Gustafsson - 0

Jon Jones - 0

Hector Lombard - 19

Benson Henderson - 9

 

The B are bench, the F are flex. The ones with o's or numbers are contracts.  The array has a field called contract_type.

 

1 = Bench.

2 = Contract

3 = Flex.

 

I need this list to order contract first, followed by flex, followed by Bench.  I can't seem to get the sort to work properly.

 

<?php
function sort_contracts( $a, $b ) { 
    echo $a->contract_type . ' - ' . $b->contract_type . '<br />';
    if ($a->contract_type == 2 && $b->contract_type == 1 || $a->contract_type == 2 && $b->contract_type == 3) { return -1; }else { return 1; }
//    if ($a->contract_type == 1 || $a->contract_type == 3) { return -1; }
//    if ($a->contract_type == 2 && $b->contract_type == 2) { return 0; }
//    if ($a->contract_type == 2 && $b->contract_type == 1) { return 1; }else { return -1; }
//    if ($a->contract_type == 2 && $b->contract_type == 3) { return 1; }else { return -1; }
}
usort($fig, 'sort_contracts');
?>

 

The commented out codes are bits/pieces of various implementations i've tried which don't work.  I can't do this at the database level (ORDER BY contract_type)

because they aren't coming out in the order I want. I don't want them ordered in 1, 2, 3 or 3, 2, 1.  I basically want to order

them in 2, 3, 1.  Any feedback on this is greatly appreciated it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.