I originally was asking questions about reversenatcase; but then silly me realised I could give myself the option of using the 'ORDER BY' capabilities of MySQL. (Don't worry though - I still need to reverse natcase thingy.)
What I want to do is parse a result from an sql query to a function.
Once I have $result; is there a way I can re-order this result?
OR would I be better off at re-querying the database using a new 'sort by' for when I want to sort by a different column of a table?? What I'm thinking is would (or COULD) a result end up being an extremely large object to parse around if I got hundreds of results in each query?
Would it rather be more efficient/'better programming' for me to re-query the database using a new 'order by'?
Thanks.
How to order a set of results without re-querying the DB?
Moderator: General Moderators
Yeah thanks - the more I think about it though, the stupider it would be to put the results into an array.
I'm thinking I'll just modify the sql query on the fly with the 'LIMIT', 'ORDER BY' and 'ASC/DESC' functions of MySQL and maintain a record of the current results being displayed and maximum results per page.
I'm thinking I'll just modify the sql query on the fly with the 'LIMIT', 'ORDER BY' and 'ASC/DESC' functions of MySQL and maintain a record of the current results being displayed and maximum results per page.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
If you're paginating the result a new query is the way to go. If not and the sort order is based on user interaction you could either reload the page with the new query or potentially use javascript to sort the results. Where possible I would tend to go the javascript route with the backup of page reload to reduce server processing and traffic.