[eluser]Unknown[/eluser]
Hi,
I am using CI and i am trying to make a sortable list with the scriptaculous/prototype library. I am able to drag and drop the table rows successfully but the database is not beeing updated.
In the sample code the sortTunes function is beeing triggered successfully, 'count($tunesList)' is 2 and the columns 'id' and 'order' exists in the database.
What can be the problem here?
view (music/_view)
Code:
<table id="table">
<tbody id="tunesList">
<tr id="item1"><td>item1</td></tr>
<tr id="item2"><td>item2</td></tr>
</tbody>
</table>
javascript
Code:
Sortable.create("tunesList",
{
tag: 'tr',
ghosting: false,
constraint: false,
onUpdate: function()
{
new Ajax.Request("music/sortTunes",
{
method: "post",
parameters: { data: Sortable.serialize("tunesList")}
}
);
}
}
);
controller (music)
Code:
function sortTunes()
{
parse_str($this->input->post('data'));
for($i=0; $i<count($tunesList); $i++)
{
$this->db->query("UPDATE tunes SET order='$i' WHERE id='$tunesList[$i]'");
}
}