title: PHP experience system // simple
body: <p>As a begginer in php programming language i'm playing with the code, working on localhost and i did some little projects.Now i am trying to do an experience system as simple as i can, i am stuck at this part and i don't know what i am doing wrong.Some suggestions?</p>
  <p>What i am doing wrong?</p>
  <p>The code.</p>
  <pre><code>function update_user_xp($user_id, $xp_ammount){
  
      global $db;
  
      $params = array('user_id' =&gt; $user_id);
  
      $users = $db-&gt;rawQuery(&quot;SELECT * FROM users_xp WHERE user_id = ?&quot;, $params);
  
      $data = array(
          'user_xp_amount' =&gt; $xp_ammount + $users[0]['user_xp_amount'],
          'user_id' =&gt; $user_id
      );
  
      $db-&gt;where ('user_id', $data['user_id']);
  
          if ($db-&gt;update ('users_xp', $data)){
  
              $xpReceived = 'You have received '.$xp_ammount.' points of experience! Have a total of '.$data['user_xp_amount'].' points of experience.';
  
          } else {
  
              $xpReceived = $db-&gt;getLastError();
          }
  
      return $xpReceived;
  }
  
  
  //update_user_xp(4, 10); // user_id: 4, update with 10 points
  
  function get_user_xp ($user_id){
      global $db;
  
      $params = array('user_id' =&gt; $user_id);
  
      $user = $db-&gt;rawQueryOne ('SELECT * FROM users_xp WHERE user_id=?', $params);
  
      $xp = $user['user_xp_amount'];
  
      return $xp;
  
  }
  
  function xp_need () {
  
      global $db;
  
      $xpBarNeed = $db-&gt;rawQuery(&quot;SELECT `level`, `expneeded` FROM `experience_level`&quot;);
  
      foreach ($xpBarNeed as $key =&gt; $value) {
  
          $output[] = $value;
  
      }
  
  
      return $output;
  
  }
  
  
  $xpn = xp_need();
  
  $userXP = get_user_xp(4);
  
  for($i = 0; $i &lt; count($xpn); $i++){
  
              if($xpn[$i]['expneeded'] == $userXP)
              {
  
                  //This part is working well
                  print 'You are level &lt;b&gt;' . $xpn[$i]['level'].'&lt;/b&gt;';
  
  
              } else {
  
                  if ($userXP &gt; $xpn[$i]['expneeded'] &amp;&amp; $userXP &gt;= $xpn[$i]['expneeded'])
              {
  
  
                          //This is the part that doesn t work, 
                          $diffEXP =  $xpn[$i]['expneeded'] -= $userXP;
  
                          print 'You need more exp  '. $diffEXP.'&lt;/br&gt;';
  
              }
          }
  
  }
  </code></pre>
  <p>This is how i am seeing in the page.
  <a href="https://prnt.sc/u7z18u" rel="nofollow noreferrer">https://prnt.sc/u7z18u</a></p>