order by alphabet PHP, MySql but list the letter before each group
<p>Say I had a table with :</p>

<pre><code>First      | Last
-------------------
Bob          Dylan
Ashley       Scott
Lol Cats
black cake
</code></pre>

<p>It would order them but do</p>

<pre><code>A:
  Ashley Scott
B:
  Bob Dylan
  Black Cake
L:
  lol cats
</code></pre>

<p>I know how to list by abc from MySql. but i want to have it put the letter before each group of names. So i can make a nice looking interface, and at the top of the page have A B C D letters at the top that went contacts#letterL</p>

<p>I know how to do the #links in a url. Its just the div Id. I know how to grab from MySql. The part i'm not sure on is echoing the letter before the group of names that start with that letter.</p>

<p>I was thinking of getting the first letter of the name of saving it in a variable.</p>

<pre><code>if ($lastletter == $currentleter) {
  echo name
} else {
  $lastletter = $currentleter;
  echo '&lt;div id="Letter ' . $currentleter .  '" class="letterheader"&gt;' . $currentleter . '&lt;/div&gt;';
}
</code></pre>

<p>Not sure if this idea would be a efficient idea. Would this be the right away of doing this?</p>
