views:

54

answers:

0

Hello,

I have a generated list of items (teams, playing in the season). I want to distribute these items to other lists (divisions for the season) and save new lists to MYSQL (order of list doesnt matter). I have to say that divisions may vary depending on the season, so i have divisions also generated from db.

I changed #sortable to .sortable . It looks like this (the data to this page come from previous page):

Sorting works well, but i cannot find a way to save that.

I refferred to this solution

The first list is an id=0, other lists are generated and are id=1, id=2, etc.

The li tag looks like this:

echo '<ul id="list0" class="connectedSortable sortable">';
echo '<li class="ui-state-default" id="'.$team_unique.'"><input type=hidden name=[team_unique] value="'.$team_unique.'">'.$club->club_shortname.' '.$count.'</li>';
echo '</ul>';

The empty ul tags, into which the teams are to be distributed, together with javascript look like this:

$divisions = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."billiards_divisions ORDER BY div_order ASC");
foreach ($divisions as $division) {

$div_id = $division->div_id;

?>

<script type="text/javascript">
        $(function() {
            $(".sortable#0, .sortable#<?php $div_id ?>").sortable({
                connectWith: '.connectedSortable',
                    update : function () 
                    { 
                $.ajax(
                {
                    type: "POST",
                    url: "phpscript",
//                  data    : $('.sortable#0, .sortable#<?php $div_id ?>').sortable('serialize'),

                    data    : 
                    {
                        sort:$(".sortable#<?php $div_id ?>").sortable('serialize'),
                    },

                    success: function(html)
                    {
                        $('.success').fadeIn(500);
                        $('.success').fadeOut(500);
                    }
                });
            }

        }).disableSelection();
    });
</script>

<?php

echo '<ul id="'.$div_id.'" class="connectedSortable sortable" size="8" style="height: 260px; width: 170px;">';
    echo '<input type=hidden name="team_unique['.$div_id.'][]" value="'.$div_id.'">';
    echo '<p>'.$division->div_name.'</p>';
echo '</ul>';

} // end of foreach ($divisions as $division)

I want to distribute teams to different divisions and after clicking button Save, to update MySQL table where next to each team_unique the div_id would be updated.

Thank you