首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery拖放表行排序不起作用

jQuery拖放表行排序不起作用
EN

Stack Overflow用户
提问于 2013-12-24 18:07:13
回答 1查看 6.3K关注 0票数 1

我想要创建一个脚本,通过拖放从数据库中订购一些行。行显示在表中,我拖放行以重新排序。每个tr都有数据库中的行id。当我拖放一行时,jquery序列化表内容并将其发送到php以保存行位置。

行位置没有保存在db中的问题是什么?

带行的表:

代码语言:javascript
复制
$select_categories = mysqli_query($db_connect, "SELECT `id`, `title` FROM `categories` ORDER BY `category_order` ASC") or die(mysqli_error());

if(mysqli_num_rows($select_categories) != 0)
{
    echo '<table cellpadding="0" cellspacing="0" class="manage_content" id="sort_rows" align="center">';

    while($category = mysqli_fetch_assoc($select_categories))
    {
        echo '
        <tr id="row-'.$category['id'].'">
            <td width="700"><a href="'.$website_address.'/admin/categories_edit.php?id='.$category['id'].'">'.$category['title'].'</a></td>
            <td><a href="'.$website_address.$_SERVER['PHP_SELF'].'?action=delete_content&amp;id='.$category['id'].'" class="delete_content">Delete</a></td>
        </tr>
        ';
    }

    echo '</table>';
}

jQuery

代码语言:javascript
复制
$("#sort_rows tbody").sortable({

    cursor: 'move',
    delay: 180,

    update: function()
    {
        var rowsOrder = $(this).sortable("serialize");

        $.post("ajax_actions.php", { action:'change_rows_order', table:'categories', order:'category_order', rows_order:rowsOrder } );
    }

}).disableSelection();

AJAX

代码语言:javascript
复制
if(isset($_POST['action']) && $_POST['action'] == 'change_rows_order')
{
    $order_no = 1;

    foreach($_POST['rows_order'] as $row_id)
    {
        $update_order = mysqli_query($db_connect, "UPDATE `".clear_tags($_POST['table'])."` SET `".clear_tags($_POST['order'])."` = '".$order_no."' WHERE `id` = '".$row_id."'") or die(mysqli_error());

        $order_no++;
    }
}

代码语言:javascript
复制
<table cellpadding="0" cellspacing="0" class="manage_content" id="sort_rows" align="center">
<tr id="row-10">
    <td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=10">Editorial</a></td>
    <td><a href="http://local.admin.com/admin/index.php?action=delete_content&amp;id=10" class="delete_content">Delete</a></td>
</tr>

<tr id="row-11">
    <td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=11">Fashion</a></td>
    <td><a href="http://local.admin.com/admin/index.php?action=delete_content&amp;id=11" class="delete_content">Delete</a></td>
</tr>

<tr id="row-12">
    <td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=12">Street Style</a></td>
    <td><a href="http://local.admin.com/admin/index.php?action=delete_content&amp;id=12" class="delete_content">Delete</a></td>
</tr>

<tr id="row-13">
    <td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=13">Portraits</a></td>
    <td><a href="http://local.admin.com/admin/index.php?action=delete_content&amp;id=13" class="delete_content">Delete</a></td>
</tr>

<tr id="row-14">
    <td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=14">Clothing</a></td>
    <td><a href="http://local.admin.com/admin/index.php?action=delete_content&amp;id=14" class="delete_content">Delete</a></td>
</tr>
</table>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-03 22:06:36

我解决了问题。我遵循了这里的教程:http://www.webresourcesdepot.com/dynamic-dragn-drop-with-jquery-and-php/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20765093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档