Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: Rank Bar

  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts

    Question Rank Bar

    How do I make an experience bar that goes up based on a $variable, and when it is 100% your rank increases one and it goes back to 0, also the amount of $variable needed to get to 100% increases?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Wait, you have to explain what you are talking about. What language are we talking, for what purpose?

    Conceptually

    Code:
    $rank = 0;
    $exp = 0;
    
    ...code to change $exp
    
    if ($exp => 100) {
    $rank++;
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Ya, the coding you did is pretty easy to make and is what I need but I also need the xp bar display. I would prefer it be in either php, mysql, java, but I think it can be done in html tables with like a background color mabey?


    Its somthing like this, but not using I's lol

    40% xp : IIIIIIIIII : 60% Remaining

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ahh ok. There are lots of ways. You can do it with just CSS even.

    Basically make two divs, set both with a background color, and with widths.

    Code:
    <div id="rank">
    <div id="percent" style="width: 25%">25%</div>
    </div>
    Code:
    #rank { width: 300px; height:20px; background-color: #FF0000; border: 1px solid #000000; }
    #percent { background-color: #00FF00; color:#000000; height:18px; padding-top:2px; text-align:right; }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    Ndogg (07-29-2009)

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    And using the example code you gave me, it would change the xp bar based on there xp?

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You would somehow have to output the number in place of the 25, I have no idea where this exp is coming from, you never said.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,786
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    Quote Originally Posted by gnomeontherun View Post
    Conceptually

    Code:
    $rank = 0;
    $exp = 0;
    
    ...code to change $exp
    
    if ($exp => 100) {
    $rank++;
    }
    Except you also have to reset $exp to zero, if I’m not entirely mistaken:

    Code:
    $rank = 0;
    $exp = 0;
    
    ...code to change $exp
    
    if ($exp => 100) {
    $rank++;
    $exp = 0;
    }

  • Users who have thanked VIPStephan for this post:

    Ndogg (07-29-2009)

  • #8
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts
    If you are pulling this data from a MySQL DB, then you need to make the appropriate DB calls. To sum up what has been said before, you need something like this...

    PHP Code:
    $rank = 0;
    $exp = 0;

    if ($exp => 100) 
    {
    $rank++;
    $exp = 0;
    }

    <div id="rank">
    <div id="percent" style="width: <?php echo $exp?>%"><?php echo $exp?></div>
    </div>
    And CSS:
    Code:
    #rank { width: 300px; height:20px; background-color: #FF0000; border: 1px solid #000000; }
    #percent { background-color: #00FF00; color:#000000; height:18px; padding-top:2px; text-align:right; }

  • Users who have thanked wldrumstcs for this post:

    Ndogg (07-29-2009)

  • #9
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Yes, I think the above will work, and its going to be comign from a DB.

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Quote Originally Posted by VIPStephan View Post
    Except you also have to reset $exp to zero, if I’m not entirely mistaken:

    Code:
    $rank = 0;
    $exp = 0;
    
    ...code to change $exp
    
    if ($exp => 100) {
    $rank++;
    $exp = 0;
    }
    I think you are entirely mistaken, well except for the reset part...
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    PHP Code:
      echo '<div id="percent" style="width: <?php echo $exp?>%"><?php echo $exp?></div>';
    This isnt working, it just keeps showing the bar completely full

  • #12
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Quote Originally Posted by Ndogg View Post
    PHP Code:
      echo '<div id="percent" style="width: <?php echo $exp?>%"><?php echo $exp?></div>';
    This isnt working, it just keeps showing the bar completely full
    You cannot embed PHP tags inside of PHP. What is this for? Not to be rude, but do you understand whats going on or what your using? I like to know that people learn from the help we give, so just ask.

    PHP Code:
      echo '<div id="rank">
    <div id="percent" style="width: '
    .$exp.'%">'.$exp.'</div>
    </div>'

    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    Ndogg (07-30-2009)

  • #13
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,786
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    Quote Originally Posted by gnomeontherun View Post
    PHP Code:
      echo '<div id="rank">
    <div id="percent" style="width: '
    .$exp.'%">'.$exp.'</div>
    </div>'

    or

    PHP Code:
    <?php
    // PHP functions here
    ?>
    <div id="rank">
    <div id="percent" style="width: <?php echo $exp?>"><?php echo $exp ?></div>
    </div>
    Sorry, gnome, I’m not trying to degrade your advice, just giving an alternative way of writing it (in case that’s what the OP had in mind).

  • #14
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Thanks Gnome, that works!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •