1

我想允许用户对从数据库派生的表行进行排序并将新位置保存在数据库 中问题是在数据库 mysql 表中的界面中没有更新位置:id int primary key auto_increment, sort int, author_affliation varchar, author_email varchar

脚本:

$('#myTable tbody').sortable({
                    start: function (event, ui) {
                        //fix firefox position issue when dragging.
                        if (navigator.userAgent.toLowerCase().match(/firefox/) && ui.helper !== undefined) {
                            ui.helper.css('position', 'absolute').css('margin-top', $(window).scrollTop());
                            //wire up event that changes the margin whenever the window scrolls.
                            $(window).bind('scroll.sortableplaylist', function () {
                                ui.helper.css('position', 'absolute').css('margin-top', $(window).scrollTop());
                            });
                        }
                    },
                    beforeStop: function (event, ui) {
                        //undo the firefox fix.
                        if (navigator.userAgent.toLowerCase().match(/firefox/) && ui.offset !== undefined) {
                            $(window).unbind('scroll.sortableplaylist');
                            ui.helper.css('margin-top', 0);
                        }
                    },
                    helper: function (e, ui) {
                        ui.children().each(function () {
                            $(this).width($(this).width());
                        });
                        return ui;
                    },
                    scroll: true,
                    update: function (event, ui) {
                        serial = $(this).sortable('serialize');
                        $.ajax({
                            url: "sort_coauthors.php",
                            type: "POST",
                            data: serial,
                            success: function(response) {
                              alert(response);
                            },
                            error: function(){
                                alert("theres an error with AJAX");
                            }
                        });
                    }
                }).disableSelection();

排序合著者:

@mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

if (isset($_POST['menu']) && is_array( $_POST['menu'])) {
$menu = $_POST['menu'];
for ($i = 0; $i < count($menu); $i++) {
    $q = mysql_query("UPDATE `co_authors` SET `sort`=" . $i . " WHERE `id`='" . intval($menu[$i]) . "'") or die(mysql_error());
if($q) {
    echo "success";
}
}
}
else {
    echo "fail";
}

主页:

while ($row = mysql_fetch_assoc($co_authors)) {

                    echo "<tbody><tr id='menu_" . $row['id'] . "'><td>{$row['author_email']}</td>
                     <td>{$row['coauthor_affliation']}</td>";
                    ?><td><button class='remove' id='remove' name='remove' email="<?php echo $row['author_email'] ?>"
                            paper="<?php echo $row['paper_id'] ?>">Remove</button></td>
4

0 回答 0