1

私がそのような単純なテーブルを持っているとしましょう:

unique ID | url | order

unique IDいつものように自動的に与えられます、url提出されなければならないものです。しかし、どうすればオードをアレンジできますか?

ユーザーが希望する順序でそれらを配置できるようにしurlたいと思います。

どうすればそれを達成できますか?その最後に挿入されたアイテムには常に最後の注文番号があり、注文番号が5から1のアイテムを移動すると、すべてのアイテムの注文番号が変わります。JavaScriptで何らかのドラッグアンドドロップを使用して実装したいのですが、現時点ではそれほど重要ではありません。

私が問題を抱えているのはPHP側です。順序付けられた番号を変更します。

4

3 に答える 3

0

you could have a dropdown or something which decides what order to display the data it would eitger be ascending or descending. Then in your SQL query end it with ORDER BY url DESC or ORDER BY url ASC

于 2012-06-01T11:12:16.187 に答える
0

You could implement this with sortable in jquery UI quite easily, it would give you an array of ids in order, from there it's just a case of doing a $.post to your php page which just iterates the array (therefore you know the order value) updates the row and sets the new order value.

Your stop function in jquery would look something like:

stop: function(event, ui) {
        var ids = [];
        ui.item.parent().children().each(function(n, element) {
            ids[ids.length] = element.id;
        });

        $.post("/somelocation", {
            orderedids: ids.toString()
        } );
    }
于 2012-06-01T11:13:12.823 に答える
0

I do exactly this, and it works fine. I use jQuery UI Sortable for the interface like this:

js:

$(document).ready(function(){ 

    function renumberSortables(){
        // Re-number the ordering i the list.

        $("ul.sortable").each(function(){
            $(this)
                .find("li")
                    .each(function(index){
                        $(this).find("input.ordering").val(index);
                    });
        });
    }

    $("ul.sortable").sortable({       
        opacity: 0.8,
        stop: renumberSortables
    }); 
}

html/php:

<ul class="sortable">
    <?php foreach($sortables as $index => $sortable){ ?>
        <li>
            <input class="ordering" type="hidden" name="sortable[<?= $index ?>][ordering]" value="<?= $sortable.ordering ?>">

            (Your stuff here…)

        </li>
    <?php } ?>
</ul>
于 2012-06-01T11:19:32.093 に答える