Hello,
My approach would be implementing the sorting options you want by conditioning the selection from the database depending on the chosen option, directly sorting the results, and display them as you want.
I look forward to working for you.
Yours Sincerely,
Alex Radu