Major Bug - Please Help

Discussion in 'PHP' started by CuBz, Dec 2, 2007.

  1. #1
    Why wont this work?

    Peoples rank is meant to change when they get the right amount of rankpoints, but it doesnt seem to be ranking them up, but their rankpoints ARE increasing.

    
    $username=$_SESSION['username'];
    
    $query=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1");
    $info = mysql_fetch_object($query);
    
    if (($info->rank == "Scruff") && ($info->rankpoints >= "100")){ $newrank="Scum Bag"; $done="1"; }
    
    elseif (($info->rank == "Scum Bag") && ($info->rankpoints >= "200")){ $newrank="Chav"; $done="1"; }
    
    elseif (($info->rank == "Chav") && ($info->rankpoints >= "300")){ $newrank="Vandal"; $done="1"; }
    
    elseif (($info->rank == "Vandal") && ($info->rankpoints >= "500")){ $newrank="Thief"; $done="1"; }
    
    elseif (($info->rank == "Thief") && ($info->rankpoints >= "800")){ $newrank="Robber"; $done="1"; }
    
    
    elseif (($info->rank == "Robber") && ($info->rankpoints >= "1300")){ $newrank="Criminal"; $done="1"; }
    
    elseif (($info->rank == "Criminal") && ($info->rankpoints >= "2100")){ $newrank="Hitman"; $done="1"; }
    
    elseif (($info->rank == "Hitman") && ($info->rankpoints >= "3400")){ $newrank="Assassinator"; $done="1"; }
    
    elseif (($info->rank == "Assassinator") && ($info->rankpoints >= "5500")){ $newrank="Boss"; $done="1"; }
    
    elseif (($info->rank == "Boss") && ($info->rankpoints >= "8900")){ $newrank="Don"; $done="1"; }
    
    elseif (($info->rank == "Don") && ($info->rankpoints >= "14400")){ $newrank="Godfather"; $done="1"; }
    
    elseif (($info->rank == "Godfather") && ($info->rankpoints >= "23300")){ $newrank="World Class Dominator"; $done="1"; }
    
    elseif (($info->rank == "World Class Dominator") && ($info->rankpoints >= "37700")){ $newrank="Untouchable Godfather"; $done="1"; }
    
    elseif (($info->rank == "Untouchable Godfather") && ($info->rankpoints >= "61000")){ $newrank="Legend"; $done="1"; }
    
    elseif (($info->rank == "Legend") && ($info->rankpoints >= "98700")){ $newrank="Mobster Legend"; $done="1"; }
    
    elseif (($info->rank == "Mobster Legend") && ($info->rankpoints >= "159700")){ $newrank="Official ML God"; $done="1"; }
    if (!$done){
    $done="0";
    }
    if ($done == "1"){
    
    mysql_query("UPDATE users SET rank='$newrank' WHERE username='$username'");
    mysql_query("INSERT INTO `inbox` ( `id` , `subject` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id` ) 
    VALUES ('', 'Rank', '$username', '$username', '[b]Congratulations! You have been promoted to $newrank!', '$date', '0', '0', '0')");
    
    }}
    PHP:
    Thanks Very Much
     
    CuBz, Dec 2, 2007 IP
  2. mvl

    mvl Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change:
    
    if (($info->rank == "Scruff") && ($info->rankpoints == "100")){ $newrank="Scum Bag"; $done="1"; }
    
    Code (markup):
    To:
    
    if (($info->rank == "Scruff") && ($info->rankpoints >= "100")){ $newrank="Scum Bag"; $done="1"; }
    
    Code (markup):
     
    mvl, Dec 2, 2007 IP
  3. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thats what it was

    Sorry i dont know how it changed, anyway it still doesnt work like that
     
    CuBz, Dec 2, 2007 IP
  4. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    HI,

    All MVL changed is >= to == in the first check.

    The issue with your query is it will always fallout in the first stage as you are checking for higher than 100 if they are then they wont move any higher.

    You either need to reverse the if statement, so it tries all the higher numbers 1st.

    
    if(($info->rank == "Mobster Legend") && ($info->rankpoints >= "159700")){ $newrank="Official ML God"; $done="1"; }
    elseif(($info->rank == "Legend") && ($info->rankpoints >= "98700")){ $newrank="Mobster Legend"; $done="1"; }
    elseif(($info->rank == "Untouchable Godfather") && ($info->rankpoints >= "61000")){ $newrank="Legend"; $done="1"; }
    elseif(($info->rank == "World Class Dominator") && ($info->rankpoints >= "37700")){ $newrank="Untouchable Godfather"; $done="1"; }
    elseif(($info->rank == "Godfather") && ($info->rankpoints >= "23300")){ $newrank="World Class Dominator"; $done="1"; }
    elseif(($info->rank == "Don") && ($info->rankpoints >= "14400")){ $newrank="Godfather"; $done="1"; }
    elseif(($info->rank == "Boss") && ($info->rankpoints >= "8900")){ $newrank="Don"; $done="1"; }
    elseif(($info->rank == "Assassinator") && ($info->rankpoints >= "5500")){ $newrank="Boss"; $done="1"; }
    elseif(($info->rank == "Hitman") && ($info->rankpoints >= "3400")){ $newrank="Assassinator"; $done="1"; }
    elseif(($info->rank == "Criminal") && ($info->rankpoints >= "2100")){ $newrank="Hitman"; $done="1"; }
    elseif(($info->rank == "Robber") && ($info->rankpoints >= "1300")){ $newrank="Criminal"; $done="1"; }
    elseif(($info->rank == "Thief") && ($info->rankpoints >= "800")){ $newrank="Robber"; $done="1"; }
    elseif(($info->rank == "Vandal") && ($info->rankpoints >= "500")){ $newrank="Thief"; $done="1"; }
    elseif(($info->rank == "Chav") && ($info->rankpoints >= "300")){ $newrank="Vandal"; $done="1"; }
    elseif(($info->rank == "Scum Bag") && ($info->rankpoints >= "200")){ $newrank="Chav"; $done="1"; }
    elseif (($info->rank == "Scruff") && ($info->rankpoints >= "100")){ $newrank="Scum Bag"; $done="1"; }
    
    PHP:
    Or you would need to use the less than sign and change the values to the next level above and not use = ( but you would also need to check it was higher than your total minimum (100)

    
    if (($info->rank == "Scruff") && ($info->rankpoints >= "100" && $info->rankpoints < "200")){ $newrank="Scum Bag"; $done="1"; }
    elseif(($info->rank == "Scum Bag") && ($info->rankpoints >= "200" && $info->rankpoints < "300")){ $newrank="Chav"; $done="1"; }
    elseif(($info->rank == "Chav") && ($info->rankpoints >= "300" && $info->rankpoints < "500")){ $newrank="Vandal"; $done="1"; }
    elseif(($info->rank == "Vandal") && ($info->rankpoints >= "500" && $info->rankpoints < "800")){ $newrank="Thief"; $done="1"; }
    elseif(($info->rank == "Thief") && ($info->rankpoints >= "800" && $info->rankpoints < "13200")){ $newrank="Robber"; $done="1"; }
    elseif(($info->rank == "Robber") && ($info->rankpoints >= "1300" && $info->rankpoints < "2100")){ $newrank="Criminal"; $done="1"; }
    elseif(($info->rank == "Criminal") && ($info->rankpoints >= "2100" && $info->rankpoints < "3400")){ $newrank="Hitman"; $done="1"; }
    elseif(($info->rank == "Hitman") && ($info->rankpoints >= "3400" && $info->rankpoints < "5500")){ $newrank="Assassinator"; $done="1"; }
    elseif(($info->rank == "Assassinator") && ($info->rankpoints >= "5500" && $info->rankpoints < "8900")){ $newrank="Boss"; $done="1"; }
    elseif(($info->rank == "Boss") && ($info->rankpoints >= "8900" && $info->rankpoints < "14400")){ $newrank="Don"; $done="1"; }
    elseif(($info->rank == "Don") && ($info->rankpoints >= "14400" && $info->rankpoints < "23300")){ $newrank="Godfather"; $done="1"; }
    elseif(($info->rank == "Godfather") && ($info->rankpoints >= "23300" && $info->rankpoints < "37700")){ $newrank="World Class Dominator"; $done="1"; }
    elseif(($info->rank == "World Class Dominator") && ($info->rankpoints >= "37700" && $info->rankpoints < "61000")){ $newrank="Untouchable Godfather"; $done="1"; }
    elseif(($info->rank == "Untouchable Godfather") && ($info->rankpoints >= "61000" && $info->rankpoints < "98700")){ $newrank="Legend"; $done="1"; }
    elseif(($info->rank == "Legend") && ($info->rankpoints >= "98700" && $info->rankpoints < "159700")){ $newrank="Mobster Legend"; $done="1"; }
    elseif(($info->rank == "Mobster Legend") && ($info->rankpoints >= "159700")){ $newrank="Official ML God"; $done="1"; }
    
    PHP:
     
    lfhost, Dec 2, 2007 IP