I have attempted to build a level system for my users in php. So far I only have a mysql table of…
id / xp (default 0) / xp_needed (default 5) / level (default 1)
I also have in my user’s panel a bar which shows how much xp is needed, $details is an array of the mysql table columns.
$xp_needed = ($details['xp'] / $details ['xp_needed']) * 100;
echo'<p>XP Needed:</p><div class="bar Tooltip" title="' . $details['xp'] . '/' .
$details['xp_needed'] . '"><span style="width: ' . $xp_needed . '%;"></span></div>';
What I can’t work out is a function for checking if the xp is over the xp needed and if so updating the level to the next integer, updating the xp needed to 5 * the level and carrying over the remainder if any of the xp_needed to the new xp_needed?
Thanks for your patience
Write a function
xpIncrease($amount), and call it everywhere you increase user’s xp.it should like this: