3

我正在使用 PHP/MYSQL。

我想创建一个用于排序图像的图像库。用户将拖放图像以对图像进行排序和组织。就像 picassa 一样。

我使用 jQuery UI 可排序插件创建了一个页面:http: //jqueryui.com/demos/sortable/#display-grid

演示页面:http: //jsbin.com/oqani/9/

它正确地拖放图像。但是在用户完成图像排序后,我无法获得图像的当前顺序。一旦我得到当前订单,我必须将该订单保存在 db 中以获取该特定图像。

假设我有图像1, 2, 3, 4, 5, 6, 7, 8, 9的顺序,然后我使用图像并且顺序变为1, 3, 4, 7, 8, 2, 5, 6, 9。因此,单击“显示订单”按钮时,它应该显示订单为1, 3, 4, 7, 8, 2, 5, 6, 9

谁能帮我在单击“显示顺序”按钮时显示图像的当前顺序,并为我提供一些关于如何将特定图像的当前顺序放入数据库中的概念。

谢谢

4

2 回答 2

1
jQuery("#contentSortableUL").sortable({
    opacity: 0.6,
    cursor: "move",
    update: function(){
        var order = $(this).sortable("serialize"); 
        jQuery.post("update-sorting.php", order, function(theResponse){
            // Callback code here
        });
    }
});

要更新数据库,您需要在 update-sorting.php 页面中编写代码:

<?php
/* code in update-sort.php would look like */
include("includes/db.connection.php");

$updateRecordsArray = $_POST['recordsArray'];
$listingCounter = 1;
$orderedImageIds = array();

foreach ($updateRecordsArray as $recordIDValue){
    $listingCounter = $listingCounter + 1;

    /* update query goes here */
    update tableName set order = $listingCounter 
}
?>

希望有帮助。

于 2011-07-05T08:29:39.890 回答
0

是的,实际上在 jQuery UI 中得到了它,有一些事件,例如updatestart等等,使用它们我们可以获得新的排序顺序。

这是最终的工作演示:http: //jsbin.com/oqani/10/

于 2010-02-24T10:09:28.560 回答