title: group by first letter alphabetically
body: <p>With the following script, values ​​are entered alphabetically sorted under the capital letter.
  However, I can't get <code>$author</code> into the while statement so it appears with 'title'.</p>
  
  <p>I want the last html part included in the while statement. But no matter what I try, it doesn't work
  What am I doing wrong?</p>
  
  <pre><code>&lt;?php
  if ($stmt = $mysqli-&gt;prepare("select `link`, `titel`, `author` from `books` where `id`=? order by `titel`asc ")) {
      $stmt-&gt;bind_param('i', $id);
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($link, $titel, $author);
      while ($stmt-&gt;fetch()) {
          $titel = mb_strimwidth("$titel", 0, 30, "...");
          $letter = substr($titel, 0, 1);
          $res[$letter][] = $titel;
  
      }
      foreach ($res as $key =&gt; $val) {
          ?&gt;
          &lt;div class="&lt;?php $letter; ?&gt;"&gt;&lt;/div&gt;
          &lt;?php
  
          echo $key; //shows capital letter
          foreach ($val as $reqvals) {
              echo $reqvals; //shows 'titel'
              echo "&lt;br&gt;";
          }
      }
      ?&gt;
  
      &lt;a href="#se_annonce&lt;?php echo $link; ?&gt;" class="popup-with-zoom-anim"&gt;
          &lt;div class="box"&gt;
              &lt;div class="author"&gt;By &lt;?php $author; ?&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/a&gt;
      &lt;?php
  
      $stmt-&gt;close();
  }
  ?&gt;  
  </code></pre>