Welcome Guest, Not a member yet? Register   Sign In
Save a re-ordered list with Jquery Sortable to DB [SOLVED]
#2

[eluser]eoinmcg[/eluser]
i've no idea how your database schema looks like but you will need to add a 'rank' field as a means to store the order of the pictures.

now when ajax sends you the array you simply need to cycle through the array and and update the rank field for each picture.

to do so it will be easier to post the item's id rather than title. e.g.
Code:
<li id="&lt;?php echo "item-".$row->id; ?&gt;">&lt;?php echo $row->title; ?&gt;</li>

also, my preferred method is to serialise the data and send it like so:
Code:
data: $(this).sortable("serialize"),

here's some code that will update the rank of each pic
Code:
$items = $this->input->post('item');
    $total_items = count($this->input->post('item'));


    for($item = 0; $item < $total_items; $item++ )
    {

            $data = array(
                'id' => $items[$item],
                'rank' => $rank = $item
            );

             $this->db->where('id', $data['id']);

            $this->db->update('your_table', $data);

        }


Messages In This Thread
Save a re-ordered list with Jquery Sortable to DB [SOLVED] - by El Forum - 12-09-2010, 02:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB