title: How to parse results from MySQL Table with PHP using row data?
body: <p>Typically when I make calls into a mysql db, I reference a column for values I need. In this particular instance however, I need to retrieve a set of rows and parse with PHP accordingly. The example is this:</p>
  
  <h2>Table format</h2>
  
  <pre><code>ID   |   Level
  -----------------
  1    |    1
  2    |    2
  3    |    2
  4    |    3
  5    |    4
  6    |    4
  </code></pre>
  
  <p>I am ultimately trying to retrieve all possible levels and count the number of results by those levels. A simple GROUP BY, COUNT() will do the trick:</p>
  
  <pre><code>'Select Level, Count(*) as counter FROM table GROUP BY Levels ORDER BY Levels ASC'
  </code></pre>
  
  <p>Which will return:</p>
  
  <h2>table_new</h2>
  
  <pre><code>Level  | Count
  --------------
  1     |   1
  2     |   2
  3     |   1
  4     |   2
  </code></pre>
  
  <p>The problem I face though is when retrieving these results with PHP, I am not quite sure how to set a variable, say 'level1' and set it to the value returned in the count column.</p>
  
  <p>I assume the logic would follow:</p>
  
  <pre><code>while ($row = $stmt-&gt;fetch()) {
     $count_level = $row['counter']
  }
  </code></pre>
  
  <p>(but then I would need to create counts for each level type. Any suggestions?</p>