title: Create Ranking base system and updating Rank
body: <p>Guys I'm new here and new to MySQL too ..</p>
  
  <p>So I am trying to create a database which manages a team record.The database contains a table named team with a set of columns as follow,</p>
  
  <ul>
  <li>TeamID </li>
  <li>TeamRank </li>
  <li>TeamName </li>
  <li>TeamWins </li>
  <li>TeamLoss </li>
  <li>TeamPoints</li>
  </ul>
  
  <p>So the agenda is to rank the teams on the basis of points, the greater the points higher the rank. </p>
  
  <pre><code>&lt;?php
  $con = mysqli_connect("", "", "", "");
  // Check connection
  if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $result = mysqli_query($con, "SET @rownum := 0;
    INSERT INTO team( TeamRank, TeamName)
    SELECT @rownum := @rownum + 1 AS TeamRank, TeamName 
    FROM (SELECT SUM(TeamRank)AS TeamRank , TeamName 
    FROM team
    GROUP BY TeamName 
    ORDER BY TeamRank DESC) as result
    ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName);"
  );
  
  echo "&lt;table border='1'&gt;
    &lt;tr&gt;
    &lt;th&gt;Rank&lt;/th&gt;
    &lt;th&gt;TeamID&lt;/th&gt;
    &lt;th&gt;TeamName&lt;/th&gt;
    &lt;th&gt;Total Points&lt;/th&gt;
    &lt;/tr&gt;";
  
  while ($row = mysqli_fetch_array($result)) {
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['TeamRank'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['TeamID'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['TeamName'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['TeamPoints'] . "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
  }
  
  echo "&lt;/table&gt;";
  
  mysqli_close($con);
  </code></pre>
  
  <p>Im recieveing this Error</p>
  
  <pre><code>Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result
  </code></pre>
  
  <p>Where am I Wrong? If there a problem with the code please guide me. </p>
  
  <p>P.S[EDIT]: All I want to do is take TeamName,TeamWins,TeamLoss and TeamPoints as input, and as the TeamPoints increase/decrease of a team its supposed to move the rank upwards/downwards and display a Ranking table.</p>