SO i have a table of information. the information is from an array $camps that i got from a mySql db.
I would like to give the user the ability to click on each separate colum title in the table to sort it by the specific column.
I have looked at sort(), uasort(), asort(), etc. but not sure exactly how to use them for multidemensional arrays.
since the array is comming from another php page/aplication, i thought it would be easier to resort the array rather than do a new SELECT query every time they want to resort the data.
which is the better and more efficient way to resort?
From my experience, I'd certainly go with mySQL (ORDER BY) in that case. It's a highly optimized database language with features such as query caching etc., which should give you way better performance than the sort functions.
You either have to query again or store the array in the Session anyway, which is arguably less scalable, particularly on large data sets.
Queries are pretty cheap in the majority of cases and it makes sense to leverage the strength of the database in returning data in the correct order -> this is exactly what databases are optimised to do.
If you really don't want to run the query more than once, you can use JavaScript to re-order the table. But IMO it's still much better to use ORDER BY.
Bookmarks