Php small error needs fixing

Discussion in 'PHP' started by XhennerzX, Aug 9, 2008.

  1. #1
    Hey, I have a rankbar on my game, and everytime someone does a crime, the rankbar goes up so it enables them to get to the next rank e.g:


    }elseif ($currank == "Bounty Killer"){
    $max = '2500';
    $old="1500";

    but the problem is, once you rank up once, the rankbar stops working and stays at 0% and says:

    Warning: Division by zero in rankbar.php on line 73

    (i took the url out :p)

    Anyways this is the code i have on line 73 of rankbar.php , see any problems?

    }
    $percent = round((($rankp-$old)/($max-$old))*100, 2);
    ?>


    Thanks
     
    XhennerzX, Aug 9, 2008 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well what means is that $max-$old == 0
    Therefore, this is what php is trying to do. Divided by 0 is undefined, which is the reason for the error.
    }
    ($rankp-$old)/[B]0[/B]
    ?>
    Code (markup):
     
    Pos1tron, Aug 9, 2008 IP
  3. XhennerzX

    XhennerzX Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for that pos1tron but the error is still the same expect now it doesn't say at 0% it just says % now.
     
    XhennerzX, Aug 9, 2008 IP
  4. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I wasn't giving a fix - I was just showing what php is trying to do to throw an error in that code bit. Sorry, but I don't know how to fix it. print() out of the script all of the variables and arrays (print_r()) for the arrays) that could have any effect upon that calculation when you rank up twice, and then manually recreate the calculations the script would do to understand what the problem is...
     
    Pos1tron, Aug 9, 2008 IP
  5. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    your code is somehow assign both $max and #old value to be the same ...
     
    payu, Aug 9, 2008 IP