Add a new field to the table called "sort_order"
Create a way for users to change the sort order. You can give them a list of items to sort and include a text box that shows the current sort order, allow them to change all the values to order them the way they want then save the values to the database.
Any places that list these items can ->orderBy('sort_order')
Another option is to list all the items they want to sort and provide "Up and down" links... clicking the up link swaps the sort_order value with the item above it... clicking the down link swaps the wort_order item below it.
Hi IanSirkit,
I like both options you proposed and perhaps I should use both. Though I like the second option you proposed better. My question: how to get the row "above" it or row "below it"?
Thanks in advance!
What I do is this
// get object one sort order smaller
row_above = "select * from table where sort_order < $sort_order_of_object_we_are_moving_up order by sort_order desc limit 1
// get object one sort order larger
row_below = "select * from table where sort_order > $sort_order_of_object_we_are_moving_down order by sort_order asc limit 1
IanSirkit said:
What I do is this
// get object one sort order smaller row_above = "select * from table where sort_order < $sort_order_of_object_we_are_moving_up order by sort_order desc limit 1 // get object one sort order larger row_below = "select * from table where sort_order > $sort_order_of_object_we_are_moving_down order by sort_order asc limit 1
Thanks - I'm going to give this a shot.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community