title: Group MySQL results into age groups based on date of birth
body: <p>I have a MySQL table, <code>persons</code>, with 3 columns, <code>id</code>, <code>name</code> &amp; <code>date_of_birth</code>. 
  My table has around 100 rows of data but this is likely to increase.</p>
  
  <p>I'd like to use PHP to output persons based on age groups, so:</p>
  
  <pre><code>20-25: 10
  26-35: 15
  36-45: 12
  46-55: 20
  55+: 30
  </code></pre>
  
  <p>Right now, I am just using PHP to grab all the dates of birth using this piece of code:</p>
  
  <pre><code>$sql2 = "SELECT date_of_birth FROM persons";
  $result2 = $conn-&gt;query($sql2);
  while($row2 = $result2-&gt;fetch_assoc()) {
      $date_of_birth = explode('-', $row2['date_of_birth']);
      $year = $date_of_birth[0];
      $month = $date_of_birth[1];
      $day = $date_of_birth[2];
      echo 'Year of Birth: '.$year.'&lt;br&gt;';
  }
  </code></pre>
  
  <p>Could someone guide me in the right direction to handle grouping my results by age group?</p>
  
  <p>I did find this in another SO thread but not sure if it would be useful in the above context: <code>SELECT TIMESTAMPDIFF(YEAR, '1970-02-01', CURDATE()) AS age</code>.</p>