5
I need to rank the DB records during paging. I don’t intend to create a field for ranking at first. Assuming I have 10 records
1) Ordenando a paginação por AZ, quero listar com o número correspondente ao rank - #N de 10
2) Quando exibir o conteúdo, preciso o número correspondente ao rank - #N de 10
• PAGINATION
#01 of 10, Lorem ipsum
#02 of 10, Lorem ipsum
...
#10 out of 10, Lorem ipsum
SELECT *,
FIND_IN_SET( score,
( SELECT GROUP_CONCAT( score ORDER BY score DESC ) FROM table )
) AS rank
FROM table limit X,X
• CONTENT
Lorem ipsum, Ranking #03 of 10
SELECT *,
FIND_IN_SET( score,
( SELECT GROUP_CONCAT( score ORDER BY score DESC ) FROM table )
) AS rank
FROM table WHERE ...
I took this SQL from an example and it’s working, but I don’t understand MYSQL and I don’t know for this case...
I wonder if there is another way to assemble this QUERY... I accept suggestions.
To facilitate understanding you would need to post the database table structure used!
– Willams de Jesus
@Willams de Jesus, do not need the structure of DB because I want to order in ascending order and there is a key worth as score. The example I posted on
stackexchange
- works but is based on points(TBL-SCORE
)– Papa Charlie
What do you call rank? The line number in the result?
– Bacco
I don’t quite understand. So you don’t want a field like the score of your examples? And such numbering would be based on what? In the alphabetical order of the results of each page?
– bfavaretto
@bfavaretto yes, assuming that the ID 05 in the pagination is listed as #2 in the AZ rank, I would also like that when accessing the content it also does the calculation to display
Posição 2 de 10
.– Papa Charlie