Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save jquery ui-sortable positions to DB

Im trying to replicate the functionality of this page (http://www.kissfm.ro/fresh-top-40/) for a friend who has a small web radio. The site is setup in wordpress fyi.

So my question is, after searching stackoverflow, how do i save/get the revised charts based on the users input? i found how to save single submittions but how do i get the final charts based on the user choice?

Thanks in advance! (code or link to tutorial welcome!)

like image 757
user899163 Avatar asked Aug 17 '11 17:08

user899163


2 Answers

make your HTML sortable, add javascript, and save to php on update.

<ul id="sortable">
    <li id="1">elem 1</li>
    <li id="2">elem 2</li>
    <li id="3">elem 3</li>
    <li id="4">elem 4</li>
</ul>

$(document).ready(function(){
    $('#sortable').sortable({
        update: function(event, ui) {
            var newOrder = $(this).sortable('toArray').toString();
            $.get('saveSortable.php', {order:newOrder});
        }
    });
});
like image 189
Mihai Iorga Avatar answered Sep 25 '22 13:09

Mihai Iorga


I know this is old, but what I do is just add a hidden input element in every LI. They would all have a the same name with [] at the end. This way, when you post the form containing the UL, you will get an array in your post values in the order you just put your list.

like image 22
Jon Koeter Avatar answered Sep 25 '22 13:09

Jon Koeter