...

View Full Version : Rank Bar



Ndogg
07-29-2009, 09:39 AM
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?

gnomeontherun
07-29-2009, 09:49 AM
Wait, you have to explain what you are talking about. What language are we talking, for what purpose?

Conceptually


$rank = 0;
$exp = 0;

...code to change $exp

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

Ndogg
07-29-2009, 10:02 AM
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

gnomeontherun
07-29-2009, 10:32 AM
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.


<div id="rank">
<div id="percent" style="width: 25%">25%</div>
</div>

#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; }

Ndogg
07-29-2009, 10:35 AM
And using the example code you gave me, it would change the xp bar based on there xp?

gnomeontherun
07-29-2009, 04:41 PM
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.

VIPStephan
07-29-2009, 04:44 PM
Conceptually


$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:


$rank = 0;
$exp = 0;

...code to change $exp

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

:D

wldrumstcs
07-29-2009, 04:57 PM
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...



$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:


#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; }

Ndogg
07-29-2009, 11:51 PM
Yes, I think the above will work, and its going to be comign from a DB.

gnomeontherun
07-30-2009, 12:14 AM
Except you also have to reset $exp to zero, if Iím not entirely mistaken:


$rank = 0;
$exp = 0;

...code to change $exp

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

:D

I think you are entirely mistaken, well except for the reset part...

Ndogg
07-30-2009, 12:44 AM
echo '<div id="percent" style="width: <?php echo $exp; ?>%"><?php echo $exp; ?></div>';


This isnt working, it just keeps showing the bar completely full

gnomeontherun
07-30-2009, 11:39 AM
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.


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

VIPStephan
07-30-2009, 12:03 PM
echo '<div id="rank">
<div id="percent" style="width: '.$exp.'%">'.$exp.'</div>
</div>';


or



<?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). ;)

Ndogg
07-30-2009, 12:18 PM
Thanks Gnome, that works!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum