title: Fetching the result array from mysql query in php, while loop issue
body: <p>I have this table in MySql db:</p>
  
  <p><img src="https://i.stack.imgur.com/LPuEx.png" alt="enter image description here"></p>
  
  <p>After running this query:</p>
  
  <pre><code>SELECT score, count(*) FROM Coaches group by score ORDER BY score DESC
  </code></pre>
  
  <p>The result table look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/pW3k4.png" alt="enter image description here"></p>
  
  <p>Now in php I try to fetch the result and iterate through the array to determine which group each coach belongs to and get his place in the ranking. Therefore I wrote this:</p>
  
  <pre><code>$groupsOfScoresQuery = "SELECT score, count(*) FROM Coaches group by score ORDER BY score DESC";
  
  $result = mysqli_query($dbc, $groupsOfScoresQuery);
  
  if ($result) {  // query did successfully run
  $response['topCoaches'] = array();
  
      if (mysqli_num_rows($result) &gt; 0)   {   
          while ( $rowScore = mysqli_fetch_array($result, MYSQLI_ASSOC) ) {
  
              $currentRanking++;
              $score = array(); // temp user array for one group of scores
              $numberOfCoaches; // Number of coaches with this particular number of scores
              $scoresGroup; // Scores in the particular group
  
              $score["scores"] = $rowScore["score"];
              $score["count"] = $rowScore["count(*)"];
              $numberOfCoaches = $score["count"];
              $scoresGroup = $score["scores"];
  
              $response["scoresGroup"] = $scoresGroup; // HERE IS THE PROBLEM
  
  .
  .
  .
  more processing
  } // end WHILE
  </code></pre>
  
  <p>Why <code>$response["scoresGroup"]</code> will always conatins the last value from the result? In this case this is <strong>123</strong>. I thought that this is the first iteration through the loop and <code>$response["scoresGroup"]</code> wll hold first element (474), during the second iteration should hold 382 ? What I'm doing wrong here? Do I use correct function to fetch result? or should I use different loop to acheive my goal? Thanks for the help in advance.</p>