I'm running a really big, intensive query, but I want the output to be sortable by the user. But to run the same query again every time (with the only change being the ORDER BY part) seems extremely wasteful.
Do you guys have any suggestions of how to best store the results of the query (session var?) and then sort them each time they're requested according to the user's preference, since I can't use mysql's ORDER BY function w/o running the query again?
My current thought is to store all the info in my own array the first time the query is run, keeping track of all the key/value pairs. Then I'll store that in a session variable. If a sort is requested, rather than run the query I'll just loop sort the array and loop through it.
But I feel like you guys probably have a better solution. Or see a flaw with my solutions. Either way, any help is appreciated!