title: Calculate overall score
body: <p>I have a database with these tables</p>
  
  <pre><code>users(name, team_id, overall_user_score)
  teams(id, name, team_score, totalscore)
  </code></pre>
  
  <p>How would I make a trigger to run after each update where its takes the score of all users in a team and the <code>team_score</code> of that team and add them together and puts it into <code>totalscore</code>.</p>
  
  <p>I dont have any code for a trigger . I have the php to show the overall score and thats about it .</p>
  
  <pre><code>function showTeamScore() {
      require "connect.php";
  
      $score = mysqli_query($connection, "SELECT * 
  FROM teams 
  WHERE id = '".$_GET['id']."'")  or die(mysqli_error($connection));
  
    while ($data = mysqli_fetch_array($score)) {
  
   echo $data['overall_score'];
    }
  
  }
  </code></pre>
  
  <p>Edit : Code and Problem update</p>
  
  <pre><code>mysqli_query($connection, "UPDATE teams SET totalscore=overall_score+IFNULL((SELECT sum(overall_user_score) FROM users WHERE team_id=id),0)") or die(mysqli_error($connection));
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/mEHUD.png" alt="enter image description here"></p>