title: PHP PDO group query results by column name
body: <p>The following PDO query is returning the results below:</p>
  
  <pre><code>$db = new PDO('....');
  $sth = $db-&gt;prepare('SELECT ...'); 
  </code></pre>
  
  <p>These are the results:</p>
  
  <pre><code> name   curso   
  ABC stack
  CDE stack
  FGH stack
  IJK stack
  LMN overflow
  OPQ overflow
  RST overflow
  </code></pre>
  
  <p>I need to build the HTML like:</p>
  
  <pre><code>&lt;p&gt;stack&lt;/p&gt;
  ABC&lt;br/&gt;
  CDE&lt;br/&gt;
  ...&lt;br/&gt;
  &lt;p&gt;overflow&lt;/p&gt;
  LMN&lt;br/&gt;
  OPQ&lt;br/&gt;
  </code></pre>
  
  <p>This is what I'm trying:</p>
  
  <pre><code>$sth-&gt;execute();
    //$curso = $sth-&gt;fetch();
    $id = $sth-&gt;fetchColumn(1);
    echo "&lt;p&gt;".mb_convert_encoding($id,'utf-8', 'iso-8859-1').'&lt;/p&gt;'; 
    while ($row = $sth-&gt;fetch(PDO::FETCH_ASSOC)) {
      echo (mb_convert_encoding($row['name'],'utf-8', 'iso-8859-1')).'&lt;br/&gt;';
    }
  </code></pre>
  
  <p>But this is removing the first name of each group, like:</p>
  
  <pre><code> &lt;p&gt;stack&lt;/p&gt;
      CDE&lt;br/&gt;
      ...&lt;br/&gt;
  </code></pre>