更改图像的顺序并在数据库中更新


Change order of images and update in database

我有一个HTML列表,我想通过拖放来更改它们的顺序,并在数据库中更新。但我不知道它是怎么做到的。你能帮我吗?我使用了HTML5可排序插件,但它不会在数据库中更新。

这是我的清单:

<ul class="sortable grid" >
    <?php
        $images = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
        $i = 0;
        foreach ($images as $value) {
    ?> 
    <li style='list-style-type: none' >
        <img src='<?php echo $value->guid;?>' width='90' />
        <a class='btn btn-danger' href='#' onclick='deletePic(<?php echo $i;?>)'>
            <i class='icon-trash icon-white'></i>
            Delete
        </a>
    </li>       
    <?php $i++; } ?>
</ul>

在 sortupdate 事件处理程序中编写 ajax 调用

$('.sortable').sortable().bind('sortupdate', function() {
   var menuId=[];
   //store list id or some other unique field to identify your image into menuId variable
 var request = $.ajax({
   url: "script.php",
   type: "POST",
   data: { id : menuId },
   dataType: "html"
 });
});