Sort order of record items |
I'm having a db table with this structure
Code: table: Items In my view I'm showing a list of all items like this: PHP Code: foreach ($items as $item) { this is the function for sorting-ordering my items PHP Code: // controller and this is my order function in item_m PHP Code: public function order($id, $category_id, $mode = 'down') {
see order_by
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
06-16-2016, 12:48 PM
(This post was last modified: 06-17-2016, 04:18 AM by ivantcholakov. Edit Reason: a typo ) Code: <?php defined('BASEPATH') OR exit('No direct script access allowed.'); You would need to adapt this code, ci() means get_instance(). Also, when you create a new item assign an initial value for its 'display_order' field, for example: Code: // Rewrite this using the pure CodeIgniter's query builder. Possible extras you could think about: 1. After "Move Up" and "Move Down" update the table using AJAX. Reloading the whole page is quite annoying. 2. Adding a button for drag and drop sorting also would be nice (AJAX), but this is harder. |
Welcome Guest, Not a member yet? Register Sign In |