I want some algorithm to make a PHP level up system I already made a system to level up people but what if people gained a huge amount of exp so they need to level up multiple times example of my code:

`if(isset($_POST['id']) && isset($_POST['amount'])) {
 $amount = $_POST['amount'];
 $user = $_POST['id'];
 $exp;$etnl;$newExp;$level;`

```
    `//select exp and etnl from DB 
    $result = DB::getInstance() ->query("SELECT exp,etnl,level FROM exp WHERE id = $user");
    $result->setFetchMode(PDO::FETCH_ASSOC);
    $row = $result->fetch();
    $exp = $row['exp'];
    $etnl = $row['etnl'];
    $level =  $row['level']
    //c where to level up user or to add exp to his ep bar
    if($amount + $exp > $etnl) {
        $etnl = $etnl * 2;
        $leftOvers = ($amount + $exp) - $etnl;
        $newExp = $leftOvers;
        $level = $level + 1;`

    $result = DB::getInstance()->prepare("UPDATE exp SET exp=?,level=?,etnl=? WHERE id=?");
    $result->execute(array($amount,$level,$etnl,$user));
    } else {
        $result = DB::getInstance()->prepare("UPDATE exp SET exp=? WHERE id=?");
        $result->execute(array($amount,$user));

    }
}`

```

`
 but this system fails if the exp could level up a person 2 times any help or any new code? BTW etnl stands for exp till next level thank you