This article will show you the fastest way to order your database results, via JavaScript (with some work in PHP). It adds some more work to your script, but once you see the results you won't use the approach of adding the ORDER By clause anymore.
I bet most of us have at some point developed an application where a list of products is retrieved from a database and shown in a table with its name, price and code. Perhaps some of us thought: "Hey, let's be nice and give the user the chance to order these results by name or price." So we placed a cute little icon near each column's header that linked to the search page with a flag in the URL to let it know we wanted the results ordered by name or price. The search script kindly did its job, adding the ORDER BY clause, and the ordered results were shown to the user.
Obviously this works, but there is a problem: you must search again in your database, and send the user the whole page with the new results.
So let's think -- the first time you load the page, the results are already in the user browser. Why must we bother the server again to retrieve the same results in a different order?
This article will show you the fastest way to order your database results, via JavaScript (with some work in PHP). It adds some more work to your script, but once you see the results you won't use the approach mentioned above anymore.