[eluser]Ludovic-r[/eluser]
Hi!
I'm working on a lightweight CMS and I need to store some datas to my DB. The datas are generated by Ajax with Jquery Sortable.
Actually, it's a list where you can drag and drop items to re-arrange the order.
Let me explain :
In my DB :
I have fields called : ID (the id :p) / order (which contains only numbers) / title (the title of the picture)
In my .js file :
Code:
$(function() {
$( "#list" ).sortable({
opacity: 0.6,
cursor: 'move',
tolerance: 'pointer',
revert: true,
items:'li',
placeholder: 'state',
forcePlaceholderSize: true,
update: function(event, ui){
//send datas to controller ----------------
$.ajax({
url: "/codeigniter/index.php/admin/save_order",
type: 'POST',
data: {
'order': $( "#list" ).sortable('toArray'),
},
success: function (data) {
$("#test").html(data);
}
});
//-------------------------------
}
});
$( "#sortable" ).disableSelection();
});
The Ajax request give me something like :
Pic_0 [0], Pic_1 [1], Pic_2 [2], Pic_3 [3],
That's the order of the list. If I drag and drop a "Pic" the Array result change (example :
Pic_2 [2], Pic_1 [1], Pic_0 [0], Pic_3 [3],)
Ok then in my controller :
Code:
function save_order()
{
$order = $this->input->post('order');
}
And in the view :
Code:
<li id="<?php echo $row->title."_".$i++; ?>">My_item</li>
Alright the question is :
How can I update the order in my DB? I'm a bit lost with all that informations so I just need a way to Update the field "order" in the DB with the order saved before.
Any help will be very very very appreciated! Thanks!