Sortable list problem

#1
[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]'");
        }
    }

#2
[eluser]Unknown[/eluser]
Ok, I've got it.
Code:
<tr id="item1"><td>item1</td></tr>
<tr id="item1"><td>item2</td></tr>
has to be:
Code:
<tr id="item_1"><td>item1</td></tr>
<tr id="item_2"><td>item2</td></tr>

(the number have to correspond with the id of the row)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.