richarro1234 Posted December 9, 2009 Share Posted December 9, 2009 Hello, So heres my problem: im trying to create a level system, so that when people do something on the site they gain XP, each level is set out in the database as such: _______ |xp | lvl | | --- |---| |100| 1 | |150| 2 | |300| 3 | |450| 4 | |700| 5 | etc etc... So that if you have that amount of xp or greater, then your that lvl (I.E i have 160 xp im lvl 2) Now, im trying to create a bar underneath it to show the percentage you have completed I.E. you have 25 xp the bar needs to show 25% of the bar full ive managed to get it to show the ammount of xp you need untill the next level, but im not sure how to convert that into a percentage and add it to the bar. Can someone help me with this please. Thanks Rich Quote Link to comment https://forums.phpfreaks.com/topic/184483-need-some-complicated-php-help-please/ Share on other sites More sharing options...
phpfan101 Posted December 9, 2009 Share Posted December 9, 2009 $exppercent = ($currentexp == 0) ? 0 : floor(($currentexp / $maxexp) * 100); that will give you a % value, just sub. in your values Quote Link to comment https://forums.phpfreaks.com/topic/184483-need-some-complicated-php-help-please/#findComment-973867 Share on other sites More sharing options...
richarro1234 Posted December 9, 2009 Author Share Posted December 9, 2009 Thanks for the reply, it has the percentage, but for some reason, just after it levels up the percentage starts at 80% instead of 0%. am i missing something? Thanks Rich Quote Link to comment https://forums.phpfreaks.com/topic/184483-need-some-complicated-php-help-please/#findComment-973876 Share on other sites More sharing options...
MadTechie Posted December 9, 2009 Share Posted December 9, 2009 Remember, you need to workout the XP required to level up, for example, if you have these values Level 1 $maxexp = 100 Level 2 $maxexp = 150 then when you start level 2 it will save 66%, because your XP would be on 100 of 150, (hence 66%) So you will need to get the differences between your current level and the next, So $currentexp should be $currentexp - $previouslevelMaxXP Quote Link to comment https://forums.phpfreaks.com/topic/184483-need-some-complicated-php-help-please/#findComment-973882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.