Say I had a table with :
First | Last
-------------------
Bob Dylan
Ashley Scott
Lol Cats
black cake
It would order them but do
A:
Ashley Scott
B:
Bob Dylan
Black Cake
L:
lol cats
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
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.
I was thinking of getting the first letter of the name of saving it in a variable.
if ($lastletter == $currentleter) {
echo name
} else {
$lastletter = $currentleter;
echo '<div id="Letter ' . $currentleter . '" class="letterheader">' . $currentleter . '</div>';
}
Not sure if this idea would be a efficient idea. Would this be the right away of doing this?
Untested code but something like this should work: