2014-11-24 90 views
0

我有一個HTML列表,我想通過拖放來更改它們的順序,並在數據庫中進行更新。但我不知道它是如何完成的。你能幫我嗎?我使用了HTML5sortable插件,但它不在db中更新。更改圖像的順序和更新數據庫

這裏是我的清單:

<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> 
+2

的OnChange那種你需要一個調用PHP頁面(您標記PHP)內的Ajax調用Ajax調用,然後在PHP頁面上,你可以按你想要的方式更新數據庫。 – 2014-11-24 14:02:31

回答

0

寫sortupdate事件處理

$('.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" 
}); 

});