order a variable to display from the highest to the lowest

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    order a variable to display from the highest to the lowest

    my code below will echo the position of the user if the number($nm) fallbetween the range so let say i have $nm = 10,4,3,3,1 respectively the position will be(staff,staff, staff,marketer, staff) instead of(marketer,sta ff,staff,staff, staff) how can i arrange so that marketer come first(marketer, staff,staff,sta ff,staff).

    Code:
    $query = "SELECT DISTINCT username,num FROM user ORDER BY num DESC LIMIT 5";
    $result = mysql_query ($query) or die('query error');
    while( $line = mysql_fetch_assoc($result)){
    
    $um = $line[username];
    $nm = $line[num];
    
    echo "name:$um";
    
    if($nm <= 50){
    echo "Position: president";
    }else if($nm <= 40){
    echo "Position: vice";
    }else if($nm <= 30){
    echo "Position: manager";
    }else if($nm <= 20){
    echo "Position: marketer";
    }else if($nm <= 10){
    echo "Position: staff";
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Actually, according to your code, everyone would be a president unless they have a num larger than 50.

    But that aside, you have a num of 3 that is assigned two positions in your example. That makes no sense.

    Comment

    Working...