2 ms·
I'm a little lost here. Why would you give the option to the user to sort by any column in the database? Wouldn't a better idea to give the user a bunch of labe
by manicdee 12y ago
I'm a little lost here. Why would you give the option to the user to sort by any column in the database? Wouldn't a better idea to give the user a bunch of labels on the displayed columns, then map between those and your predetermined sort orders?
You'd then have to validate the input (horrors!) and then add the appropriate sort order to the query (builder) in your own code.
Thus you present the user with column labels such as "Item", "Description", "Weight", "Packing volume", "List Price", which internally map to something like %sort_orders = { 'Item' => \&item_sort_order, 'Description' => \&description_sort_order, … } with your code doing a lookup along the lines of if exists $sort_orders{$request_sort_label} …
Of course this isn't going to be as simple and elegant as allowing user input to pass directly into your database engine.
But then for every problem there is at least one answer which is simple, elegant, and completely wrong.