简体   繁体   中英

Alphabet “pagination” check if there are records for each letter

I want to be able to create an alphabet pagination of some sort, where you have AZ and each have a link to filter by letter, however, I want to be able to label the letters with a background indicating that there are records that starts with the letter.

It looks like this so far, showing labelled letters:

在此处输入图片说明

On another thing, I'm using pagination for the results which is obviously using LIMIT on the query, so I cannot use SUBSTRING on the column then lay them out with the letters, I was wondering if it's possible to do it in one query while the search picks out the records with the records that starts with the letter.

I need to be able to show the letters that has the filled background, indicating that there is at least one record per letter, if there isn't any records to a letter, it shouldn't show the filled background.

Is it possible to do this; within one query?

I was wondering if it's possible to do it in one query

The wish of having everything in just one query makes no sense. Each query should do one and just one particular piece of work.

So your script obviously consists of 2 parts for now:

  1. Retrieve a set of records paginated by LIMIT
  2. Retrieve the distinct list of first letters

So perform 2 different queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM