I did the pagination for data I’m retrieving from the database. when I’m trying to sort each page separately it’s not working. It’s like it’s ordering the whole chunk of data and spreading it on both pages. I need to sort the contents of each page separately…
Q1:
SELECT `firstName`, `lastName`, `creationDate`, `applicationStatus`
FROM student
ORDER BY firstName ASC LIMIT 0 , 25
Q2:
SELECT `firstName`, `lastName`, `creationDate`, `applicationStatus`
FROM student
ORDER BY firstName DESC LIMIT 25 , 25
Q2 gives me a chunk of Q1’s data but in the opposite order of Q1. what I need is the same output of Q2 but sorted in both ways… and it’s not happening!
That’s how the ORDER BY clause works. If you want to sort each page independently, you need to either select it into a temporary table and ORDER BY that, or sort it in your program.