Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:52:41+00:00 2026-05-22T21:52:41+00:00

Say I had a table with : First | Last ——————- Bob Dylan Ashley

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:52:42+00:00Added an answer on May 22, 2026 at 9:52 pm

    Untested code but something like this should work:

    $currentleter = substr($name , 0 , 1);
    if ($lastletter != $currentleter){
        echo '<div id="Letter' . $currentleter .  '" class="letterheader">' . $currentleter . '</div>';
        $lastletter = $currentleter;
    }
    
    echo $name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you design you database if say you had a table called user:
Say if I had a table of books in a MySQL database and I
Say I had a MySQL table which sorts relationships between users (where there is
Say I had the following code: % Cellmode_subfunction_test.m %% Cell 1 foo(1); %% Cell
Say I had the following HTML: <h2>Heading <span></span></h2> <ul> <li><a href=# title=I am wanting
Say I had (foolishly) setup a Silverlight project in VS and failed to setup
Let's say I had a program in C# that did something computationally expensive, like
Let's say you had to calculate the sine (cosine or tangent - whatever) where
Let's say I had: protected void performLogic(List<Object> docs) { ... } In the code
I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.