Show only letters from username in database

I think itโ€™s really simple, but I canโ€™t lower my head.

I would like to achieve something like this: Get all the names from the database. Get the first letter for each name. Show all 26 letters of the alphabet + numbers: ABCDEF, etc. .... 0-9

And just put a link to the characters that are the first letter of the username. In other words, something like this:

User names from the database โ†’ Moonwalker, Tester, Admin, Tutorial, Arial

All characters are visible:

ABCDEFGH I JKLMNOPQRSTUVWXYZ 0 1 2 3 4 5 6 7 8 9

but only letters that have the same first letter as usernames are associated with something:

A BCDEFGH I JKL M NOPQRS T UVWXYZ 0 1 2 3 4 5 6 7 8 9

I know that this is possible, but I do not know how to do it.

Thanks in advance.

+3
source share
2 answers

Here's how you can get the first letter:

SELECT LEFT(`name`, 1) AS first_letter
  FROM users

Here's how you can find users using the first letter (with the first B):

SELECT `name`
  FROM users
 WHERE `name` LIKE 'B%'

Here's how you can get a list of the first letters that exist in the database (with an optional number of entries):

  SELECT LEFT(`name`, 1) AS first_letter,
         COUNT(*) AS occurrences
    FROM users
GROUP BY first_letter
+7
source


I would prefer to grab all the necessary users from the database and group them by the first letter in PHP. Here you can find something similar: http://php.bigresource.com/Track/php-A1gPapjn/

, . .

- ,

+1

Source: https://habr.com/ru/post/1781158/


All Articles